コード例 #1
0
ファイル: client.go プロジェクト: opentable/sous
func splitHost(in string) (url string, ref reference.Named, err error) {
	ref, err = reference.ParseNamed(in)
	if err != nil {
		return
	}

	url, name := reference.SplitHostname(ref)
	ref, err = updateName(ref, name)
	return
}
コード例 #2
0
ファイル: inspect.go プロジェクト: doublek420/skopeo
func validateName(name string) error {
	distref, err := distreference.ParseNamed(name)
	if err != nil {
		return err
	}
	hostname, _ := distreference.SplitHostname(distref)
	if hostname == "" {
		return fmt.Errorf("Please use a fully qualified repository name")
	}
	return nil
}
コード例 #3
0
ファイル: config.go プロジェクト: Neverous/other-docker
// splitReposName breaks a reposName into an index name and remote name
func splitReposName(reposName reference.Named) (indexName string, remoteName reference.Named, err error) {
	var remoteNameStr string
	indexName, remoteNameStr = reference.SplitHostname(reposName)
	if indexName == "" || (!strings.Contains(indexName, ".") &&
		!strings.Contains(indexName, ":") && indexName != "localhost") {
		// This is a Docker Index repos (ex: samalba/hipache or ubuntu)
		// 'docker.io'
		indexName = IndexName
		remoteName = reposName
	} else {
		remoteName, err = reference.WithName(remoteNameStr)
	}
	return
}
コード例 #4
0
ファイル: docker.go プロジェクト: invenfantasy/kubernetes
// Check if the inspected image matches what we are looking for
func matchImageTagOrSHA(inspected dockertypes.ImageInspect, image string) bool {

	// The image string follows the grammar specified here
	// https://github.com/docker/distribution/blob/master/reference/reference.go#L4
	named, err := dockerref.ParseNamed(image)
	if err != nil {
		glog.V(4).Infof("couldn't parse image reference %q: %v", image, err)
		return false
	}
	_, isTagged := named.(dockerref.Tagged)
	digest, isDigested := named.(dockerref.Digested)
	if !isTagged && !isDigested {
		// No Tag or SHA specified, so just return what we have
		return true
	}
	if isTagged {
		hostname, _ := dockerref.SplitHostname(named)
		// Check the RepoTags for an exact match
		for _, tag := range inspected.RepoTags {
			// Deal with image with hostname specified
			if len(hostname) > 0 {
				if strings.HasSuffix(image, tag) {
					return true
				}

			} else {
				if tag == image {
					// We found a specific tag that we were looking for
					return true
				}
			}
		}
	}
	if isDigested {
		algo := digest.Digest().Algorithm().String()
		sha := digest.Digest().Hex()
		// Look specifically for short and long sha(s)
		if strings.Contains(inspected.ID, algo+":"+sha) {
			// We found the short or long SHA requested
			return true
		}
	}
	glog.V(4).Infof("Inspected image (%q) does not match %s", inspected.ID, image)
	return false
}
コード例 #5
0
ファイル: util.go プロジェクト: rootfs/origin
// GetImageRegistryAuth retrieves the appropriate docker client authentication object for a given
// image name and a given set of client authentication objects.
func GetImageRegistryAuth(auths *AuthConfigurations, imageName string) api.AuthConfig {
	glog.V(5).Infof("Getting docker credentials for %s", imageName)
	namedReference, err := reference.ParseNamed(imageName)
	if err != nil {
		glog.V(0).Infof("error: Failed to parse docker reference %s", imageName)
		return api.AuthConfig{}
	}

	hostname, _ := reference.SplitHostname(namedReference)
	if strings.ContainsAny(hostname, ":.") || hostname == "localhost" {
		if auth, ok := auths.Configs[hostname]; ok {
			glog.V(5).Infof("Using %s[%s] credentials for pulling %s", auth.Email, hostname, imageName)
			return auth
		}
	}
	if auth, ok := auths.Configs[defaultRegistry]; ok {
		glog.V(5).Infof("Using %s credentials for pulling %s", auth.Email, imageName)
		return auth
	}
	return api.AuthConfig{}
}