github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/pkg/providers/common/get_image.go (about) 1 package common 2 3 import ( 4 "github.com/emc-advanced-dev/pkg/errors" 5 "github.com/solo-io/unik/pkg/providers" 6 "github.com/solo-io/unik/pkg/types" 7 "strings" 8 ) 9 10 func GetImage(p providers.Provider, nameOrIdPrefix string) (*types.Image, error) { 11 images, err := p.ListImages() 12 if err != nil { 13 return nil, errors.New("retrieving image list", err) 14 } 15 for _, image := range images { 16 if strings.Contains(image.Id, nameOrIdPrefix) || strings.Contains(image.Name, nameOrIdPrefix) { 17 return image, nil 18 } 19 } 20 return nil, errors.New("image with name or id containing '"+nameOrIdPrefix+"' not found", nil) 21 }