func (i *ImageTarget) GetRegistry() string {
	return i.registry
}
GetRegistry returns the registry of a ImageTarget
package transfer
import (
	"context"
	"fmt"
	"io"
	"github.com/opencontainers/go-digest"
	"github.com/containers/image/v5/docker"
	"github.com/containers/image/v5/types"
	"tkestack.io/image-transfer/pkg/utils"
)
type ImageTarget struct {
	registry   string
	repository string
	tag        string
	targetRef  types.ImageReference
	target     types.ImageDestination
	ctx        context.Context
	sysctx    *types.SystemContext
}
func NewImageTarget(registry, repository, tag, username, password string, insecure bool) (*ImageTarget, error) {
	if utils.CheckIfIncludeTag(repository) {
		return nil, fmt.Errorf("repository string should not include tag")
	}
	tagWithColon := ""
	if tag != "" {
		tagWithColon = ":" + tag
	}
	destRef, err := docker.ParseReference("//" + registry + "/" + repository + tagWithColon)
	if err != nil {
		return nil, err
	}
	var sysctx *types.SystemContext
	if insecure {
		sysctx = &types.SystemContext{
			DockerInsecureSkipTLSVerify: types.OptionalBoolTrue,
		}
	} else {
		sysctx = &types.SystemContext{}
	}
	ctx := context.WithValue(context.Background(), interface{}("ImageTarget"), repository)
	if username != "" && password != "" {
		sysctx.DockerAuthConfig = &types.DockerAuthConfig{
			Username: username,
			Password: password,
		}
	}
	rawtarget, err := destRef.NewImageDestination(ctx, sysctx)
	if err != nil {
		return nil, err
	}
	return &ImageTarget{
		targetRef: destRef,
		target:    rawtarget,
		ctx:       ctx,
		sysctx: sysctx,
		registry:   registry,
		repository: repository,
		tag:        tag,
	}, nil
}
func (i *ImageTarget) PushManifest(manifestByte []byte) error {
	return i.target.PutManifest(i.ctx, manifestByte, nil)
}
func (i *ImageTarget) PutABlob(blob io.ReadCloser, blobInfo types.BlobInfo) error {
	_, err := i.target.PutBlob(i.ctx, blob, types.BlobInfo{
		Digest: blobInfo.Digest,
		Size:   blobInfo.Size,
	}, Memory, true)
	defer blob.Close()
	return err
}
func (i *ImageTarget) CheckBlobExist(blobInfo types.BlobInfo) (bool, error) {
	exist, _, err := i.target.TryReusingBlob(i.ctx, types.BlobInfo{
		Digest: blobInfo.Digest,
		Size:   blobInfo.Size,
	}, Memory, false)
	return exist, err
}
func (i *ImageTarget) Close() error {
	return i.target.Close()
}