func parseEnvs(envArray []string) ([]api.EnvVar, error) { envs := []api.EnvVar{} for _, env := range envArray { parts := strings.Split(env, "=") if len(parts) != 2 || !validation.IsCIdentifier(parts[0]) || len(parts[1]) == 0 { return nil, fmt.Errorf("invalid env: %v", env) } envVar := api.EnvVar{Name: parts[0], Value: parts[1]} envs = append(envs, envVar) } return envs, nil }
func validateEnv(vars []kapi.EnvVar) fielderrors.ValidationErrorList { allErrs := fielderrors.ValidationErrorList{} for i, ev := range vars { vErrs := fielderrors.ValidationErrorList{} if len(ev.Name) == 0 { vErrs = append(vErrs, fielderrors.NewFieldRequired("name")) } if !kvalidation.IsCIdentifier(ev.Name) { vErrs = append(vErrs, fielderrors.NewFieldInvalid("name", ev.Name, "must match regex "+kvalidation.CIdentifierFmt)) } allErrs = append(allErrs, vErrs.PrefixIndex(i)...) } return allErrs }
func ValidateStrategyEnv(vars []kapi.EnvVar, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} for i, ev := range vars { idxPath := fldPath.Index(i) if len(ev.Name) == 0 { allErrs = append(allErrs, field.Required(idxPath.Child("name"), "")) } else if !kvalidation.IsCIdentifier(ev.Name) { allErrs = append(allErrs, field.Invalid(idxPath.Child("name"), ev.Name, cIdentifierErrorMsg)) } if ev.ValueFrom != nil { allErrs = append(allErrs, field.Invalid(idxPath.Child("valueFrom"), ev.ValueFrom, "valueFrom is not supported in build strategy environment variables")) } } return allErrs }
func validateEnv(vars []kapi.EnvVar, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} for i, ev := range vars { vErrs := field.ErrorList{} idxPath := fldPath.Child("name").Index(i) if len(ev.Name) == 0 { vErrs = append(vErrs, field.Required(idxPath, "")) } if !kvalidation.IsCIdentifier(ev.Name) { vErrs = append(vErrs, field.Invalid(idxPath, ev.Name, "must match regex "+kvalidation.CIdentifierFmt)) } allErrs = append(allErrs, vErrs...) } return allErrs }
func validateEnv(vars []kapi.EnvVar, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} for i, ev := range vars { vErrs := field.ErrorList{} idxPath := fldPath.Index(i).Child("name") if len(ev.Name) == 0 { vErrs = append(vErrs, field.Required(idxPath, "")) } if errs := kvalidation.IsCIdentifier(ev.Name); len(errs) > 0 { vErrs = append(vErrs, field.Invalid(idxPath, ev.Name, strings.Join(errs, ", "))) } allErrs = append(allErrs, vErrs...) } return allErrs }
func parseV1Envs(envArray []string) ([]v1.EnvVar, error) { envs := []v1.EnvVar{} for _, env := range envArray { pos := strings.Index(env, "=") if pos == -1 { return nil, fmt.Errorf("invalid env: %v", env) } name := env[:pos] value := env[pos+1:] if len(name) == 0 || !validation.IsCIdentifier(name) || len(value) == 0 { return nil, fmt.Errorf("invalid env: %v", env) } envVar := v1.EnvVar{Name: name, Value: value} envs = append(envs, envVar) } return envs, nil }