github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/tiltfile/value/name.go (about) 1 package value 2 3 import ( 4 "fmt" 5 6 "go.starlark.net/starlark" 7 "k8s.io/apimachinery/pkg/api/validation/path" 8 ) 9 10 // Names in Tilt should be valid Kubernetes API names. 11 // 12 // We use the loosest validation rules: valid path segment names. 13 // 14 // For discussion, see: 15 // https://github.com/tilt-dev/tilt/issues/4309 16 type Name string 17 18 func (n *Name) Unpack(v starlark.Value) error { 19 str, ok := AsString(v) 20 if !ok { 21 return fmt.Errorf("Value should be convertible to string, but is type %s", v.Type()) 22 } 23 24 if errs := path.ValidatePathSegmentName(str, false); len(errs) != 0 { 25 return fmt.Errorf("invalid value %q: %v", str, errs[0]) 26 } 27 28 *n = Name(str) 29 return nil 30 } 31 32 func (n Name) String() string { 33 return string(n) 34 }