func TestServiceRegistryMakeLinkVariables(t *testing.T) { service := api.Service{ JSONBase: api.JSONBase{ID: "foo"}, Selector: map[string]string{"bar": "baz"}, ContainerPort: util.IntOrString{Kind: util.IntstrString, StrVal: "a-b-c"}, } vars := makeLinkVariables(service, "mars") for _, v := range vars { if !util.IsCIdentifier(v.Name) { t.Errorf("Environment variable name is not valid: %v", v.Name) } } }
func validateEnv(vars []EnvVar) errorList { allErrs := errorList{} for i := range vars { ev := &vars[i] // so we can set default values if len(ev.Name) == 0 { allErrs.Append(makeInvalidError("EnvVar.Name", ev.Name)) } if !util.IsCIdentifier(ev.Name) { allErrs.Append(makeInvalidError("EnvVar.Name", ev.Name)) } } return allErrs }
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 !util.IsCIdentifier(ev.Name) { vErrs = append(vErrs, fielderrors.NewFieldInvalid("name", ev.Name, "must match regex "+util.CIdentifierFmt)) } allErrs = append(allErrs, vErrs.PrefixIndex(i)...) } return allErrs }
func validateEnv(vars []api.EnvVar) errs.ValidationErrorList { allErrs := errs.ValidationErrorList{} for i, ev := range vars { vErrs := errs.ValidationErrorList{} if len(ev.Name) == 0 { vErrs = append(vErrs, errs.NewFieldRequired("name", ev.Name)) } if !util.IsCIdentifier(ev.Name) { vErrs = append(vErrs, errs.NewFieldInvalid("name", ev.Name, cIdentifierErrorMsg)) } allErrs = append(allErrs, vErrs.PrefixIndex(i)...) } return allErrs }
func validateEnv(vars []api.EnvVar) errs.ValidationErrorList { allErrs := errs.ValidationErrorList{} for i := range vars { vErrs := errs.ValidationErrorList{} ev := &vars[i] // so we can set default values if len(ev.Name) == 0 { vErrs = append(vErrs, errs.NewFieldRequired("name", ev.Name)) } if !util.IsCIdentifier(ev.Name) { vErrs = append(vErrs, errs.NewFieldInvalid("name", ev.Name, "")) } allErrs = append(allErrs, vErrs.PrefixIndex(i)...) } return allErrs }
func validateEnv(vars []EnvVar) error { for i := range vars { ev := &vars[i] // so we can set default values if len(ev.Name) == 0 { // Backwards compat. if len(ev.Key) == 0 { return makeInvalidError("EnvVar.Name", ev.Name) } glog.Warning("DEPRECATED: EnvVar.Key has been replaced by EnvVar.Name") ev.Name = ev.Key ev.Key = "" } if !util.IsCIdentifier(ev.Name) { return makeInvalidError("EnvVar.Name", ev.Name) } } return nil }
func TestServiceRegistryMakeLinkVariables(t *testing.T) { service := api.Service{ JSONBase: api.JSONBase{ID: "foo-bar"}, Selector: map[string]string{"bar": "baz"}, ContainerPort: util.IntOrString{Kind: util.IntstrString, StrVal: "a-b-c"}, } registry := registrytest.NewServiceRegistry() registry.List = api.ServiceList{ Items: []api.Service{service}, } machine := "machine" vars, err := GetServiceEnvironmentVariables(registry, machine) if err != nil { t.Errorf("Unexpected err: %v", err) } for _, v := range vars { if !util.IsCIdentifier(v.Name) { t.Errorf("Environment variable name is not valid: %v", v.Name) } } }
func validateEnv(vars []EnvVar) errorList { allErrs := errorList{} for i := range vars { ev := &vars[i] // so we can set default values if len(ev.Name) == 0 { // Backwards compat. if len(ev.Key) == 0 { allErrs.Append(makeInvalidError("EnvVar.Name", ev.Name)) } else { glog.Warning("DEPRECATED: EnvVar.Key has been replaced by EnvVar.Name") ev.Name = ev.Key ev.Key = "" } } if !util.IsCIdentifier(ev.Name) { allErrs.Append(makeInvalidError("EnvVar.Name", ev.Name)) } } return allErrs }