|
|
@ -21,9 +21,12 @@ import (
|
|
|
|
"github.com/kubernetes/deployment-manager/common"
|
|
|
|
"github.com/kubernetes/deployment-manager/common"
|
|
|
|
"github.com/kubernetes/deployment-manager/util"
|
|
|
|
"github.com/kubernetes/deployment-manager/util"
|
|
|
|
"golang.org/x/oauth2"
|
|
|
|
"golang.org/x/oauth2"
|
|
|
|
|
|
|
|
"golang.org/x/oauth2/google"
|
|
|
|
|
|
|
|
storage "google.golang.org/api/storage/v1"
|
|
|
|
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
"net/url"
|
|
|
|
"regexp"
|
|
|
|
"regexp"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
@ -40,15 +43,16 @@ type registryProvider struct {
|
|
|
|
sync.RWMutex
|
|
|
|
sync.RWMutex
|
|
|
|
rs common.RegistryService
|
|
|
|
rs common.RegistryService
|
|
|
|
grp GithubRegistryProvider
|
|
|
|
grp GithubRegistryProvider
|
|
|
|
|
|
|
|
gcsrp GCSRegistryProvider
|
|
|
|
cp common.CredentialProvider
|
|
|
|
cp common.CredentialProvider
|
|
|
|
registries map[string]Registry
|
|
|
|
registries map[string]Registry
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewDefaultRegistryProvider(cp common.CredentialProvider) RegistryProvider {
|
|
|
|
func NewDefaultRegistryProvider(cp common.CredentialProvider, rs common.RegistryService) RegistryProvider {
|
|
|
|
return NewRegistryProvider(nil, NewGithubRegistryProvider(cp), cp)
|
|
|
|
return NewRegistryProvider(rs, NewGithubRegistryProvider(cp), NewGCSRegistryProvider(cp), cp)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewRegistryProvider(rs common.RegistryService, grp GithubRegistryProvider, cp common.CredentialProvider) RegistryProvider {
|
|
|
|
func NewRegistryProvider(rs common.RegistryService, grp GithubRegistryProvider, gcsrp GCSRegistryProvider, cp common.CredentialProvider) RegistryProvider {
|
|
|
|
if rs == nil {
|
|
|
|
if rs == nil {
|
|
|
|
rs = NewInmemRegistryService()
|
|
|
|
rs = NewInmemRegistryService()
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -61,11 +65,27 @@ func NewRegistryProvider(rs common.RegistryService, grp GithubRegistryProvider,
|
|
|
|
grp = NewGithubRegistryProvider(cp)
|
|
|
|
grp = NewGithubRegistryProvider(cp)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if gcsrp == nil {
|
|
|
|
|
|
|
|
gcsrp = NewGCSRegistryProvider(cp)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
registries := make(map[string]Registry)
|
|
|
|
registries := make(map[string]Registry)
|
|
|
|
rp := ®istryProvider{rs: rs, grp: grp, cp: cp, registries: registries}
|
|
|
|
rp := ®istryProvider{rs: rs, grp: grp, gcsrp: gcsrp, cp: cp, registries: registries}
|
|
|
|
return rp
|
|
|
|
return rp
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (rp registryProvider) getRegistry(cr common.Registry) (Registry, error) {
|
|
|
|
|
|
|
|
switch cr.Type {
|
|
|
|
|
|
|
|
case common.GithubRegistryType:
|
|
|
|
|
|
|
|
return rp.grp.GetGithubRegistry(cr)
|
|
|
|
|
|
|
|
case common.GCSRegistryType:
|
|
|
|
|
|
|
|
log.Printf("Creating a bigstore client using %#v", rp.gcsrp)
|
|
|
|
|
|
|
|
return rp.gcsrp.GetGCSRegistry(cr)
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("unknown registry type: %s", cr.Type)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (rp registryProvider) GetRegistryByShortURL(URL string) (Registry, error) {
|
|
|
|
func (rp registryProvider) GetRegistryByShortURL(URL string) (Registry, error) {
|
|
|
|
rp.RLock()
|
|
|
|
rp.RLock()
|
|
|
|
defer rp.RUnlock()
|
|
|
|
defer rp.RUnlock()
|
|
|
@ -77,7 +97,7 @@ func (rp registryProvider) GetRegistryByShortURL(URL string) (Registry, error) {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
r, err := rp.grp.GetGithubRegistry(*cr)
|
|
|
|
r, err := rp.getRegistry(*cr)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -111,7 +131,7 @@ func (rp registryProvider) GetRegistryByName(registryName string) (Registry, err
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
r, err := rp.grp.GetGithubRegistry(*cr)
|
|
|
|
r, err := rp.getRegistry(*cr)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -143,21 +163,21 @@ type githubRegistryProvider struct {
|
|
|
|
// NewGithubRegistryProvider creates a GithubRegistryProvider.
|
|
|
|
// NewGithubRegistryProvider creates a GithubRegistryProvider.
|
|
|
|
func NewGithubRegistryProvider(cp common.CredentialProvider) GithubRegistryProvider {
|
|
|
|
func NewGithubRegistryProvider(cp common.CredentialProvider) GithubRegistryProvider {
|
|
|
|
if cp == nil {
|
|
|
|
if cp == nil {
|
|
|
|
panic(fmt.Errorf("CP IS NIL: %v", cp))
|
|
|
|
panic(fmt.Errorf("no credential provider"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return &githubRegistryProvider{cp: cp}
|
|
|
|
return &githubRegistryProvider{cp: cp}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (grp githubRegistryProvider) createGithubClient(credentialName string) (*github.Client, error) {
|
|
|
|
func (grp githubRegistryProvider) createGithubClient(credentialName string) (*http.Client, *github.Client, error) {
|
|
|
|
if credentialName == "" {
|
|
|
|
if credentialName == "" {
|
|
|
|
return github.NewClient(nil), nil
|
|
|
|
return http.DefaultClient, github.NewClient(nil), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c, err := grp.cp.GetCredential(credentialName)
|
|
|
|
c, err := grp.cp.GetCredential(credentialName)
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Failed to fetch credential %s: %v", credentialName, err)
|
|
|
|
log.Printf("Failed to fetch credential %s: %v", credentialName, err)
|
|
|
|
log.Print("Trying to use unauthenticated client")
|
|
|
|
log.Print("Trying to use unauthenticated client")
|
|
|
|
return github.NewClient(nil), nil
|
|
|
|
return http.DefaultClient, github.NewClient(nil), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if c != nil {
|
|
|
|
if c != nil {
|
|
|
@ -166,44 +186,90 @@ func (grp githubRegistryProvider) createGithubClient(credentialName string) (*gi
|
|
|
|
&oauth2.Token{AccessToken: string(c.APIToken)},
|
|
|
|
&oauth2.Token{AccessToken: string(c.APIToken)},
|
|
|
|
)
|
|
|
|
)
|
|
|
|
tc := oauth2.NewClient(oauth2.NoContext, ts)
|
|
|
|
tc := oauth2.NewClient(oauth2.NoContext, ts)
|
|
|
|
return github.NewClient(tc), nil
|
|
|
|
return tc, github.NewClient(tc), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if c.BasicAuth.Username != "" && c.BasicAuth.Password != "" {
|
|
|
|
if c.BasicAuth.Username != "" && c.BasicAuth.Password != "" {
|
|
|
|
tp := github.BasicAuthTransport{
|
|
|
|
tp := github.BasicAuthTransport{
|
|
|
|
Username: c.BasicAuth.Username,
|
|
|
|
Username: c.BasicAuth.Username,
|
|
|
|
Password: c.BasicAuth.Password,
|
|
|
|
Password: c.BasicAuth.Password,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return github.NewClient(tp.Client()), nil
|
|
|
|
return tp.Client(), github.NewClient(tp.Client()), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, fmt.Errorf("No suitable credential found for %s", credentialName)
|
|
|
|
return nil, nil, fmt.Errorf("No suitable credential found for %s", credentialName)
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetGithubRegistry returns a new GithubRegistry. If there's a credential that is specified, will try
|
|
|
|
// GetGithubRegistry returns a new GithubRegistry. If there's a credential that is specified, will try
|
|
|
|
// to fetch it and use it, and if there's no credential found, will fall back to unauthenticated client.
|
|
|
|
// to fetch it and use it, and if there's no credential found, will fall back to unauthenticated client.
|
|
|
|
func (grp githubRegistryProvider) GetGithubRegistry(cr common.Registry) (GithubRegistry, error) {
|
|
|
|
func (grp githubRegistryProvider) GetGithubRegistry(cr common.Registry) (GithubRegistry, error) {
|
|
|
|
if cr.Type == common.GithubRegistryType {
|
|
|
|
// If there's a credential that we need to use, fetch it and create a client for it.
|
|
|
|
// If there's a credential that we need to use, fetch it and create a client for it.
|
|
|
|
httpClient, client, err := grp.createGithubClient(cr.CredentialName)
|
|
|
|
client, err := grp.createGithubClient(cr.CredentialName)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fMap := ParseRegistryFormat(cr.Format)
|
|
|
|
fMap := ParseRegistryFormat(cr.Format)
|
|
|
|
if fMap[common.UnversionedRegistry] && fMap[common.OneLevelRegistry] {
|
|
|
|
if fMap[common.UnversionedRegistry] && fMap[common.OneLevelRegistry] {
|
|
|
|
return NewGithubPackageRegistry(cr.Name, cr.URL, nil, client)
|
|
|
|
return NewGithubPackageRegistry(cr.Name, cr.URL, nil, httpClient, client)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if fMap[common.VersionedRegistry] && fMap[common.CollectionRegistry] {
|
|
|
|
if fMap[common.VersionedRegistry] && fMap[common.CollectionRegistry] {
|
|
|
|
return NewGithubTemplateRegistry(cr.Name, cr.URL, nil, client)
|
|
|
|
return NewGithubTemplateRegistry(cr.Name, cr.URL, nil, httpClient, client)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("unknown registry format: %s", cr.Format)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GCSRegistryProvider is a factory for GCS Registry instances.
|
|
|
|
|
|
|
|
type GCSRegistryProvider interface {
|
|
|
|
|
|
|
|
GetGCSRegistry(cr common.Registry) (ObjectStorageRegistry, error)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type gcsRegistryProvider struct {
|
|
|
|
|
|
|
|
cp common.CredentialProvider
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// NewGCSRegistryProvider creates a GCSRegistryProvider.
|
|
|
|
|
|
|
|
func NewGCSRegistryProvider(cp common.CredentialProvider) GCSRegistryProvider {
|
|
|
|
|
|
|
|
if cp == nil {
|
|
|
|
|
|
|
|
panic(fmt.Errorf("no credential provider"))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return &gcsRegistryProvider{cp: cp}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GetGCSRegistry returns a new Google Cloud Storage . If there's a credential that is specified, will try
|
|
|
|
|
|
|
|
// to fetch it and use it, and if there's no credential found, will fall back to unauthenticated client.
|
|
|
|
|
|
|
|
func (gcsrp gcsRegistryProvider) GetGCSRegistry(cr common.Registry) (ObjectStorageRegistry, error) {
|
|
|
|
|
|
|
|
// If there's a credential that we need to use, fetch it and create a client for it.
|
|
|
|
|
|
|
|
if cr.CredentialName == "" {
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("No CredentialName specified for %s", cr.Name)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
client, err := gcsrp.createGCSClient(cr.CredentialName)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
service, err := storage.New(client)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.Fatalf("Unable to create storage service: %v", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return NewGCSRegistry(cr.Name, cr.URL, client, service)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("unknown registry format: %s", cr.Format)
|
|
|
|
func (gcsrp gcsRegistryProvider) createGCSClient(credentialName string) (*http.Client, error) {
|
|
|
|
|
|
|
|
c, err := gcsrp.cp.GetCredential(credentialName)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.Printf("Failed to fetch credential %s: %v", credentialName, err)
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("Failed to fetch Credential %s: %s", credentialName, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("unknown registry type: %s", cr.Type)
|
|
|
|
config, err := google.JWTConfigFromJSON([]byte(c.ServiceAccount), storage.DevstorageReadOnlyScope)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.Fatalf("Unable to parse client secret file to config: %v", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return config.Client(oauth2.NoContext), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// RE for a registry type that does support versions and has collections.
|
|
|
|
// RE for a registry type that does support versions and has collections.
|
|
|
@ -212,6 +278,9 @@ var TemplateRegistryMatcher = regexp.MustCompile("github.com/(.*)/(.*)/(.*)/(.*)
|
|
|
|
// RE for a registry type that does not support versions and does not have collections.
|
|
|
|
// RE for a registry type that does not support versions and does not have collections.
|
|
|
|
var PackageRegistryMatcher = regexp.MustCompile("github.com/(.*)/(.*)/(.*)")
|
|
|
|
var PackageRegistryMatcher = regexp.MustCompile("github.com/(.*)/(.*)/(.*)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// RE for GCS storage
|
|
|
|
|
|
|
|
var GCSRegistryMatcher = regexp.MustCompile("gs://(.*)/(.*)")
|
|
|
|
|
|
|
|
|
|
|
|
// IsGithubShortType returns whether a given type is a type description in a short format to a github repository type.
|
|
|
|
// IsGithubShortType returns whether a given type is a type description in a short format to a github repository type.
|
|
|
|
// For now, this means using github types:
|
|
|
|
// For now, this means using github types:
|
|
|
|
// github.com/owner/repo/qualifier/type:version
|
|
|
|
// github.com/owner/repo/qualifier/type:version
|
|
|
@ -231,24 +300,31 @@ func IsGithubShortPackageType(t string) bool {
|
|
|
|
return PackageRegistryMatcher.MatchString(t)
|
|
|
|
return PackageRegistryMatcher.MatchString(t)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// IsGCSShortType returns whether a given type is a type description in a short format to GCS
|
|
|
|
|
|
|
|
func IsGCSShortType(t string) bool {
|
|
|
|
|
|
|
|
return strings.HasPrefix(t, "gs://")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetDownloadURLs checks a type to see if it is either a short git hub url or a fully specified URL
|
|
|
|
// GetDownloadURLs checks a type to see if it is either a short git hub url or a fully specified URL
|
|
|
|
// and returns the URLs that should be used to fetch it. If the url is not fetchable (primitive type
|
|
|
|
// and returns the URLs that should be used to fetch it. If the url is not fetchable (primitive type
|
|
|
|
// for example), it returns an empty slice.
|
|
|
|
// for example), it returns an empty slice.
|
|
|
|
func GetDownloadURLs(rp RegistryProvider, t string) ([]string, error) {
|
|
|
|
func GetDownloadURLs(rp RegistryProvider, t string) ([]string, Registry, error) {
|
|
|
|
if IsGithubShortType(t) {
|
|
|
|
if IsGithubShortType(t) {
|
|
|
|
return ShortTypeToDownloadURLs(rp, t)
|
|
|
|
return ShortTypeToDownloadURLs(rp, t)
|
|
|
|
} else if IsGithubShortPackageType(t) {
|
|
|
|
} else if IsGithubShortPackageType(t) {
|
|
|
|
return ShortTypeToPackageDownloadURLs(rp, t)
|
|
|
|
return ShortTypeToPackageDownloadURLs(rp, t)
|
|
|
|
|
|
|
|
} else if IsGCSShortType(t) {
|
|
|
|
|
|
|
|
return ShortTypeToGCSDownloadUrls(rp, t)
|
|
|
|
} else if util.IsHttpUrl(t) {
|
|
|
|
} else if util.IsHttpUrl(t) {
|
|
|
|
result, err := url.Parse(t)
|
|
|
|
result, err := url.Parse(t)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("cannot parse download URL %s: %s", t, err)
|
|
|
|
return nil, nil, fmt.Errorf("cannot parse download URL %s: %s", t, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return []string{result.String()}, nil
|
|
|
|
return []string{result.String()}, nil, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return []string{}, nil
|
|
|
|
return []string{}, nil, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ShortTypeToDownloadURLs converts a github URL into downloadable URL from github.
|
|
|
|
// ShortTypeToDownloadURLs converts a github URL into downloadable URL from github.
|
|
|
@ -256,15 +332,15 @@ func GetDownloadURLs(rp RegistryProvider, t string) ([]string, error) {
|
|
|
|
// github.com/owner/repo/qualifier/type:version
|
|
|
|
// github.com/owner/repo/qualifier/type:version
|
|
|
|
// for example:
|
|
|
|
// for example:
|
|
|
|
// github.com/kubernetes/application-dm-templates/storage/redis:v1
|
|
|
|
// github.com/kubernetes/application-dm-templates/storage/redis:v1
|
|
|
|
func ShortTypeToDownloadURLs(rp RegistryProvider, t string) ([]string, error) {
|
|
|
|
func ShortTypeToDownloadURLs(rp RegistryProvider, t string) ([]string, Registry, error) {
|
|
|
|
m := TemplateRegistryMatcher.FindStringSubmatch(t)
|
|
|
|
m := TemplateRegistryMatcher.FindStringSubmatch(t)
|
|
|
|
if len(m) != 6 {
|
|
|
|
if len(m) != 6 {
|
|
|
|
return nil, fmt.Errorf("cannot parse short github url: %s", t)
|
|
|
|
return nil, nil, fmt.Errorf("cannot parse short github url: %s", t)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
r, err := rp.GetRegistryByShortURL(t)
|
|
|
|
r, err := rp.GetRegistryByShortURL(t)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if r == nil {
|
|
|
|
if r == nil {
|
|
|
@ -273,15 +349,15 @@ func ShortTypeToDownloadURLs(rp RegistryProvider, t string) ([]string, error) {
|
|
|
|
|
|
|
|
|
|
|
|
tt, err := NewType(m[3], m[4], m[5])
|
|
|
|
tt, err := NewType(m[3], m[4], m[5])
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, r, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
urls, err := r.GetDownloadURLs(tt)
|
|
|
|
urls, err := r.GetDownloadURLs(tt)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, r, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return util.ConvertURLsToStrings(urls), err
|
|
|
|
return util.ConvertURLsToStrings(urls), r, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ShortTypeToPackageDownloadURLs converts a github URL into downloadable URLs from github.
|
|
|
|
// ShortTypeToPackageDownloadURLs converts a github URL into downloadable URLs from github.
|
|
|
@ -289,26 +365,48 @@ func ShortTypeToDownloadURLs(rp RegistryProvider, t string) ([]string, error) {
|
|
|
|
// github.com/owner/repo/type
|
|
|
|
// github.com/owner/repo/type
|
|
|
|
// for example:
|
|
|
|
// for example:
|
|
|
|
// github.com/helm/charts/cassandra
|
|
|
|
// github.com/helm/charts/cassandra
|
|
|
|
func ShortTypeToPackageDownloadURLs(rp RegistryProvider, t string) ([]string, error) {
|
|
|
|
func ShortTypeToPackageDownloadURLs(rp RegistryProvider, t string) ([]string, Registry, error) {
|
|
|
|
m := PackageRegistryMatcher.FindStringSubmatch(t)
|
|
|
|
m := PackageRegistryMatcher.FindStringSubmatch(t)
|
|
|
|
if len(m) != 4 {
|
|
|
|
if len(m) != 4 {
|
|
|
|
return nil, fmt.Errorf("Failed to parse short github url: %s", t)
|
|
|
|
return nil, nil, fmt.Errorf("Failed to parse short github url: %s", t)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
r, err := rp.GetRegistryByShortURL(t)
|
|
|
|
r, err := rp.GetRegistryByShortURL(t)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tt, err := NewType("", m[3], "")
|
|
|
|
tt, err := NewType("", m[3], "")
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, r, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
urls, err := r.GetDownloadURLs(tt)
|
|
|
|
urls, err := r.GetDownloadURLs(tt)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, r, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return util.ConvertURLsToStrings(urls), r, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return util.ConvertURLsToStrings(urls), err
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|