// ShortTypeToDownloadURLs converts a github URL into downloadable URL from github.
// Input must be of the type and is assumed to have been validated before this call:
// github.com/owner/repo/qualifier/type:version
// for example:
// github.com/kubernetes/application-dm-templates/storage/redis:v1
func ShortTypeToDownloadURLs(rp RegistryProvider, t string) ([]string, Registry, error) {
	m := TemplateRegistryMatcher.FindStringSubmatch(t)
	if len(m) != 6 {
		return nil, nil, fmt.Errorf("cannot parse short github url: %s", t)
	}

	r, err := rp.GetRegistryByShortURL(t)
	if err != nil {
		return nil, nil, err
	}

	if r == nil {
		panic(fmt.Errorf("cannot get github registry for %s", t))
	}

	tt, err := NewType(m[3], m[4], m[5])
	if err != nil {
		return nil, r, err
	}

	urls, err := r.GetDownloadURLs(tt)
	if err != nil {
		return nil, r, err
	}

	return util.ConvertURLsToStrings(urls), r, err
}
// ShortTypeToGCSDownloadUrls returns the download URLs for a short type name.
func ShortTypeToGCSDownloadUrls(rp RegistryProvider, t string) ([]string, Registry, error) {
	m := GCSRegistryMatcher.FindStringSubmatch(t)
	if len(m) != 3 {
		return nil, nil, fmt.Errorf("Failed to parse short gs url: %s", t)
	}

	r, err := rp.GetRegistryByShortURL(t)
	if err != nil {
		return nil, nil, err
	}
	tt, err := NewType(m[1], m[2], "")
	if err != nil {
		return nil, r, err
	}

	urls, err := r.GetDownloadURLs(tt)
	if err != nil {
		return nil, r, err
	}
	return util.ConvertURLsToStrings(urls), r, err
}
Пример #3
0
// ShortTypeToPackageDownloadURLs converts a github URL into downloadable URLs from github.
// Input must be of the type and is assumed to have been validated before this call:
// github.com/owner/repo/type
// for example:
// github.com/helm/charts/cassandra
func ShortTypeToPackageDownloadURLs(rp RegistryProvider, t string) ([]string, error) {
	m := PackageRegistryMatcher.FindStringSubmatch(t)
	if len(m) != 4 {
		return nil, fmt.Errorf("Failed to parse short github url: %s", t)
	}

	r, err := rp.GetRegistryByShortURL(t)
	if err != nil {
		return nil, err
	}

	tt, err := NewType("", m[3], "")
	if err != nil {
		return nil, err
	}

	urls, err := r.GetDownloadURLs(tt)
	if err != nil {
		return nil, err
	}

	return util.ConvertURLsToStrings(urls), err
}