@@ -11,6 +11,7 @@ import (
1111
1212 "github.com/commitdev/zero/internal/config/globalconfig"
1313 "github.com/commitdev/zero/internal/config/moduleconfig"
14+ "github.com/commitdev/zero/internal/constants"
1415 "github.com/commitdev/zero/internal/util"
1516 "github.com/commitdev/zero/pkg/credentials"
1617 "github.com/commitdev/zero/pkg/util/exit"
@@ -88,7 +89,20 @@ func ValidateSAK(input string) error {
8889 return nil
8990}
9091
91- // TODO: validation / allow prompt retry ...etc
92+ // ValidateProjectName validates Project Name field user input.
93+ func ValidateProjectName (input string ) error {
94+ // the first 62 char out of base64 and -
95+ var pName = regexp .MustCompile (`^[A-Za-z0-9-]{1,16}$` )
96+ if ! pName .MatchString (input ) {
97+ // error if char len is greater than 16
98+ if len (input ) > constants .MaxPnameLength {
99+ return errors .New ("Invalid, Project Name: (cannot exceed a max length of 16)" )
100+ }
101+ return errors .New ("Invalid, Project Name: (can only contain alphanumeric chars & '-')" )
102+ }
103+ return nil
104+ }
105+
92106func (p PromptHandler ) GetParam (projectParams map [string ]string ) string {
93107 var err error
94108 var result string
@@ -170,18 +184,31 @@ func sanitizeParameterValue(str string) string {
170184
171185// PromptParams renders series of prompt UI based on the config
172186func PromptModuleParams (moduleConfig moduleconfig.ModuleConfig , parameters map [string ]string , projectCredentials globalconfig.ProjectCredential ) (map [string ]string , error ) {
173-
174187 credentialEnvs := projectCredentials .SelectedVendorsCredentialsAsEnv (moduleConfig .RequiredCredentials )
175188 for _ , promptConfig := range moduleConfig .Parameters {
176189 // deduplicate fields already prompted and received
177190 if _ , isAlreadySet := parameters [promptConfig .Field ]; isAlreadySet {
178191 continue
179192 }
180193
194+ var validateFunc func (input string ) error = nil
195+
196+ // type:regex field validation for zero-module.yaml
197+ if promptConfig .FieldValidation .Type == constants .RegexValidation {
198+ validateFunc = func (input string ) error {
199+ var regexRule = regexp .MustCompile (promptConfig .FieldValidation .Value )
200+ if ! regexRule .MatchString (input ) {
201+ return errors .New (promptConfig .FieldValidation .ErrorMessage )
202+ }
203+ return nil
204+ }
205+ }
206+ // TODO: type:fuction field validation for zero-module.yaml
207+
181208 promptHandler := PromptHandler {
182209 Parameter : promptConfig ,
183210 Condition : NoCondition ,
184- Validate : NoValidation ,
211+ Validate : validateFunc ,
185212 }
186213 // merging the context of param and credentals
187214 // this treats credentialEnvs as throwaway, parameters is shared between modules
0 commit comments