// ReplaceImage replaces an image.
// The name is the file name that will be displayed on SmugMug.
// The data is the raw image data.
168167
func (c *Conn) ReplaceImage(name string, data []byte, image *Image) (*Image, error) {
	return c.upload(name, data, "ImageID", image.ID)
}
812868
func (s *BuildConfiguration) SetImage(v string) *BuildConfiguration {
	s.Image = &v
	return s
}
428787
func NormalizeImageName(image string) string {
	if !strings.Contains(image, ":") {
		return fmt.Sprintf("%s:latest", image)
	}
	return image
}
997998
func matchImage(s *drone.Secret, image string) bool {
	for _, pattern := range s.Images {
		if match, _ := filepath.Match(pattern, image); match {
			return true
		} else if pattern == "*" {
			return true
		}
	}
	return false
}
243694
func (api *API) DeleteImage(img_id string) (*Image, error) {
	result := new(Image)
	url := createUrl(api, imagePathSegment, img_id)
	err := api.Client.Delete(url, nil, &result, http.StatusAccepted)
	if err != nil {
		return nil, err
	}
	result.api = api
	return result, nil
}
352016
func (d *driverOCI) DeleteImage(ctx context.Context, id string) error {
	_, err := d.computeClient.DeleteImage(ctx, core.DeleteImageRequest{ImageId: &id})
	return err
}
590292
func NewImage(conf *Config) (*Image, error) {
	tr := &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: conf.InsecureTLS},
		Proxy:           http.ProxyFromEnvironment,
	}
	client := http.Client{
		Transport: tr,
		Timeout:   conf.Timeout,
	}
	registry := dockerHub
	tag := "latest"
	token := ""
	os := "linux"
	arch := "amd64"
	var nameParts, tagParts []string
	var name, port string
	state := stateInitial
	start := 0
	for i, c := range conf.ImageName {
		if c == ':' || c == '/' || c == '@' || i == len(conf.ImageName)-1 {
			if i == len(conf.ImageName)-1 {
				// ignore a separator, include the last symbol
				i += 1
			}
			part := conf.ImageName[start:i]
			start = i + 1
			switch state {
			case stateInitial:
				if part == "localhost" || strings.Contains(part, ".") {
					// it's registry, let's check what's next =port of image name
					registry = part
					if c == ':' {
						state = statePort
					} else {
						state = stateName
					}
				} else {
					// it's an image name, if separator is /
					// next part is also part of the name
					// othrewise it's an offcial image
					if c == '/' {
						// we got just a part of name, till next time
						start = 0
						state = stateName
					} else {
						state = stateTag
						name = fmt.Sprintf("library/%s", part)
					}
				}
			case stateTag:
				tag = ""
				tagParts = append(tagParts, part)
			case statePort:
				state = stateName
				port = part
			case stateName:
				if c == ':' || c == '@' {
					state = stateTag
				}
				nameParts = append(nameParts, part)
			}
		}
	}

	if port != "" {
		registry = fmt.Sprintf("%s:%s", registry, port)
	}
	if name == "" {
		name = strings.Join(nameParts, "/")
	}
	if tag == "" {
		tag = strings.Join(tagParts, ":")
	}
	if conf.InsecureRegistry {
		registry = fmt.Sprintf("http://%s/v2", registry)
	} else {
		registry = fmt.Sprintf("https://%s/v2", registry)
	}
	if conf.Token != "" {
		token = "Basic " + conf.Token
	}
	if conf.PlatformOS != "" {
		os = conf.PlatformOS
	}
	if conf.PlatformArch != "" {
		arch = conf.PlatformArch
	}

	return &Image{
		Registry: registry,
		Name:     name,
		Tag:      tag,
		user:     conf.User,
		password: conf.Password,
		Token:    token,
		client:   client,
		os:       os,
		arch:     arch,
	}, nil
}
808762
func (a *SetDockTileArgs) SetImage(image string) *SetDockTileArgs {
	a.Image = &image
	return a
}
48986
func (dh *Client) DeleteImage(name string) error {
	if name == "" {
		return fmt.Errorf("no image name given")
	}

	req, e := http.NewRequest("DELETE", dh.Address+"/images/"+name, nil)
	if e != nil {
		return e
	}

	resp, e := dh.Client.Do(req)
	if e != nil {
		return e
	}
	defer resp.Body.Close()

	if !success(resp) {
		return fmt.Errorf("failed to delete image %s", name)
	}
	return nil
}
854227
func (s *PutImageOutput) SetImage(v *Image) *PutImageOutput {
	s.Image = v
	return s
}
1358233
func (daemon *Daemon) LoadImage(inTar io.ReadCloser, name string, refs map[string]string, outStream io.Writer) error {
	imageExporter := tarexport.NewTarExporter(daemon.ImageStore(), daemon.LayerStore(), daemon.ReferenceStore())
	return imageExporter.Load(inTar, name, refs, outStream)
}
1041639
func (c *Client) GetImage(ctx context.Context, ref string) (Image, error) {
	i, err := c.ImageService().Get(ctx, ref)
	if err != nil {
		return nil, err
	}
	return NewImage(c, i), nil
}
1198741
func (c *Cluster) RemoveImage(name string) error {
	stor := c.storage()
	image, err := stor.RetrieveImage(name)
	if err != nil {
		return err
	}
	hosts := []string{}
	idMap := map[string][]string{}
	for _, entry := range image.History {
		_, isOld := idMap[entry.Node]
		idMap[entry.Node] = append(idMap[entry.Node], entry.ImageId)
		if !isOld {
			hosts = append(hosts, entry.Node)
		}
	}
	_, err = c.runOnNodes(func(n node) (interface{}, error) {
		imgIds, _ := idMap[n.addr]
		err = n.RemoveImage(name)
		_, isNetErr := err.(net.Error)
		if err == docker.ErrConnectionRefused {
			isNetErr = true
		}
		if err != nil && err != docker.ErrNoSuchImage && !isNetErr {
			return nil, err
		}
		for _, imgId := range imgIds {
			// Errors are ignored here because we're just ensuring any
			// remaining data that wasn't removed when calling remove with the
			// image name is removed now, no big deal if there're errors here.
			n.RemoveImage(imgId)
			stor.RemoveImage(name, imgId, n.addr)
		}
		return nil, nil
	}, docker.ErrNoSuchImage, true, hosts...)
	return err
}
383528
func ImageName(conf *yaml.Config) error {
	for _, image := range conf.Pipeline {
		image.Image = strings.Replace(image.Image, "_", "-", -1)
	}
	return nil
}
85143
func PullImage(ctx context.Context, client client.ImageAPIClient, serviceName string, authLookup auth.Lookup, image string) error {
	fmt.Fprintf(os.Stderr, "Pulling %s (%s)...\n", serviceName, image)
	distributionRef, err := reference.ParseNormalizedNamed(image)
	if err != nil {
		return err
	}

	repoInfo, err := registry.ParseRepositoryInfo(distributionRef)
	if err != nil {
		return err
	}

	authConfig := authLookup.Lookup(repoInfo)

	// Use ConfigFile.SaveToWriter to not re-define encodeAuthToBase64
	encodedAuth, err := encodeAuthToBase64(authConfig)
	if err != nil {
		return err
	}

	options := types.ImagePullOptions{
		RegistryAuth: encodedAuth,
	}
	responseBody, err := client.ImagePull(ctx, distributionRef.String(), options)
	if err != nil {
		logrus.Errorf("Failed to pull image %s: %v", image, err)
		return err
	}
	defer responseBody.Close()

	var writeBuff io.Writer = os.Stderr

	outFd, isTerminalOut := term.GetFdInfo(os.Stderr)

	err = jsonmessage.DisplayJSONMessagesStream(responseBody, writeBuff, outFd, isTerminalOut, nil)
	if err != nil {
		if jerr, ok := err.(*jsonmessage.JSONError); ok {
			// If no error code is set, default to 1
			if jerr.Code == 0 {
				jerr.Code = 1
			}
			fmt.Fprintf(os.Stderr, "%s", writeBuff)
			return fmt.Errorf("Status: %s, Code: %d", jerr.Message, jerr.Code)
		}
	}
	return err
}
1195416
func (i *ImageService) LoadImage(inTar io.ReadCloser, outStream io.Writer, quiet bool) error {
	imageExporter := tarexport.NewTarExporter(i.imageStore, i.layerStores, i.referenceStore, i)
	return imageExporter.Load(inTar, outStream, quiet)
}
1259287
func ParseImageName(image string) (string, string) {
	repoToPull, tag := parsers.ParseRepositoryTag(image)
	// If no tag was specified, use the default "latest".
	if len(tag) == 0 {
		tag = defaultImageTag
	}
	return repoToPull, tag
}