github.com/YousefHaggyHeroku/pack@v1.5.5/internal/registry/buildpack.go (about) 1 package registry 2 3 import ( 4 "fmt" 5 "strings" 6 7 ggcrname "github.com/google/go-containerregistry/pkg/name" 8 "github.com/pkg/errors" 9 10 "github.com/YousefHaggyHeroku/pack/internal/style" 11 ) 12 13 // Buildpack contains information about a buildpack stored in a Registry 14 type Buildpack struct { 15 Namespace string `json:"ns"` 16 Name string `json:"name"` 17 Version string `json:"version"` 18 Yanked bool `json:"yanked"` 19 Address string `json:"addr,omitempty"` 20 } 21 22 // Validate that a buildpack reference contains required information 23 func Validate(b Buildpack) error { 24 if b.Address == "" { 25 return errors.New("invalid entry: address is a required field") 26 } 27 _, err := ggcrname.NewDigest(b.Address) 28 if err != nil { 29 return fmt.Errorf("invalid entry: '%s' is not a digest reference", b.Address) 30 } 31 32 return nil 33 } 34 35 // ParseNamespaceName parses a buildpack ID into Namespace and Name 36 func ParseNamespaceName(id string) (ns string, name string, err error) { 37 parts := strings.Split(id, "/") 38 if len(parts) < 2 { 39 return "", "", fmt.Errorf("invalid id %s does not contain a namespace", style.Symbol(id)) 40 } else if len(parts) > 2 { 41 return "", "", fmt.Errorf("invalid id %s contains unexpected characters", style.Symbol(id)) 42 } 43 44 return parts[0], parts[1], nil 45 }