|
|
@ -29,28 +29,28 @@ import (
|
|
|
|
"sync"
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// RepoProvider is a factory for ChartRepo instances.
|
|
|
|
// RepoProvider is a factory for IChartRepo instances.
|
|
|
|
type RepoProvider interface {
|
|
|
|
type RepoProvider interface {
|
|
|
|
GetRepoByURL(URL string) (ChartRepo, error)
|
|
|
|
GetRepoByURL(URL string) (IChartRepo, error)
|
|
|
|
GetRepoByName(repoName string) (ChartRepo, error)
|
|
|
|
GetRepoByName(repoName string) (IChartRepo, error)
|
|
|
|
GetChartByReference(reference string) (*chart.Chart, error)
|
|
|
|
GetChartByReference(reference string) (*chart.Chart, error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type repoProvider struct {
|
|
|
|
type repoProvider struct {
|
|
|
|
sync.RWMutex
|
|
|
|
sync.RWMutex
|
|
|
|
rs Service
|
|
|
|
rs IRepoService
|
|
|
|
cp CredentialProvider
|
|
|
|
cp ICredentialProvider
|
|
|
|
gcsrp GCSRepoProvider
|
|
|
|
gcsrp GCSRepoProvider
|
|
|
|
repos map[string]ChartRepo
|
|
|
|
repos map[string]IChartRepo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// NewRepoProvider creates a new repository provider.
|
|
|
|
// NewRepoProvider creates a new repository provider.
|
|
|
|
func NewRepoProvider(rs Service, gcsrp GCSRepoProvider, cp CredentialProvider) RepoProvider {
|
|
|
|
func NewRepoProvider(rs IRepoService, gcsrp GCSRepoProvider, cp ICredentialProvider) RepoProvider {
|
|
|
|
return newRepoProvider(rs, gcsrp, cp)
|
|
|
|
return newRepoProvider(rs, gcsrp, cp)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// newRepoProvider creates a new repository provider.
|
|
|
|
// newRepoProvider creates a new repository provider.
|
|
|
|
func newRepoProvider(rs Service, gcsrp GCSRepoProvider, cp CredentialProvider) *repoProvider {
|
|
|
|
func newRepoProvider(rs IRepoService, gcsrp GCSRepoProvider, cp ICredentialProvider) *repoProvider {
|
|
|
|
if rs == nil {
|
|
|
|
if rs == nil {
|
|
|
|
rs = NewInmemRepoService()
|
|
|
|
rs = NewInmemRepoService()
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -63,18 +63,18 @@ func newRepoProvider(rs Service, gcsrp GCSRepoProvider, cp CredentialProvider) *
|
|
|
|
gcsrp = NewGCSRepoProvider(cp)
|
|
|
|
gcsrp = NewGCSRepoProvider(cp)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
repos := make(map[string]ChartRepo)
|
|
|
|
repos := make(map[string]IChartRepo)
|
|
|
|
rp := &repoProvider{rs: rs, gcsrp: gcsrp, cp: cp, repos: repos}
|
|
|
|
rp := &repoProvider{rs: rs, gcsrp: gcsrp, cp: cp, repos: repos}
|
|
|
|
return rp
|
|
|
|
return rp
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetRepoService returns the repository service used by this repository provider.
|
|
|
|
// GetRepoService returns the repository service used by this repository provider.
|
|
|
|
func (rp *repoProvider) GetRepoService() Service {
|
|
|
|
func (rp *repoProvider) GetRepoService() IRepoService {
|
|
|
|
return rp.rs
|
|
|
|
return rp.rs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetCredentialProvider returns the credential provider used by this repository provider.
|
|
|
|
// GetCredentialProvider returns the credential provider used by this repository provider.
|
|
|
|
func (rp *repoProvider) GetCredentialProvider() CredentialProvider {
|
|
|
|
func (rp *repoProvider) GetCredentialProvider() ICredentialProvider {
|
|
|
|
return rp.cp
|
|
|
|
return rp.cp
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -84,7 +84,7 @@ func (rp *repoProvider) GetGCSRepoProvider() GCSRepoProvider {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetRepoByName returns the repository with the given name.
|
|
|
|
// GetRepoByName returns the repository with the given name.
|
|
|
|
func (rp *repoProvider) GetRepoByName(repoName string) (ChartRepo, error) {
|
|
|
|
func (rp *repoProvider) GetRepoByName(repoName string) (IChartRepo, error) {
|
|
|
|
rp.Lock()
|
|
|
|
rp.Lock()
|
|
|
|
defer rp.Unlock()
|
|
|
|
defer rp.Unlock()
|
|
|
|
|
|
|
|
|
|
|
@ -100,7 +100,7 @@ func (rp *repoProvider) GetRepoByName(repoName string) (ChartRepo, error) {
|
|
|
|
return rp.createRepoByType(cr)
|
|
|
|
return rp.createRepoByType(cr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (rp *repoProvider) createRepoByType(r Repo) (ChartRepo, error) {
|
|
|
|
func (rp *repoProvider) createRepoByType(r IRepo) (IChartRepo, error) {
|
|
|
|
switch r.GetType() {
|
|
|
|
switch r.GetType() {
|
|
|
|
case GCSRepoType:
|
|
|
|
case GCSRepoType:
|
|
|
|
cr, err := rp.gcsrp.GetGCSRepo(r)
|
|
|
|
cr, err := rp.gcsrp.GetGCSRepo(r)
|
|
|
@ -114,7 +114,7 @@ func (rp *repoProvider) createRepoByType(r Repo) (ChartRepo, error) {
|
|
|
|
return nil, fmt.Errorf("unknown repository type: %s", r.GetType())
|
|
|
|
return nil, fmt.Errorf("unknown repository type: %s", r.GetType())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (rp *repoProvider) createRepo(cr ChartRepo) (ChartRepo, error) {
|
|
|
|
func (rp *repoProvider) createRepo(cr IChartRepo) (IChartRepo, error) {
|
|
|
|
name := cr.GetName()
|
|
|
|
name := cr.GetName()
|
|
|
|
if _, ok := rp.repos[name]; ok {
|
|
|
|
if _, ok := rp.repos[name]; ok {
|
|
|
|
return nil, fmt.Errorf("respository named %s already exists", name)
|
|
|
|
return nil, fmt.Errorf("respository named %s already exists", name)
|
|
|
@ -125,7 +125,7 @@ func (rp *repoProvider) createRepo(cr ChartRepo) (ChartRepo, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetRepoByURL returns the repository whose URL is a prefix of the given URL.
|
|
|
|
// GetRepoByURL returns the repository whose URL is a prefix of the given URL.
|
|
|
|
func (rp *repoProvider) GetRepoByURL(URL string) (ChartRepo, error) {
|
|
|
|
func (rp *repoProvider) GetRepoByURL(URL string) (IChartRepo, error) {
|
|
|
|
rp.Lock()
|
|
|
|
rp.Lock()
|
|
|
|
defer rp.Unlock()
|
|
|
|
defer rp.Unlock()
|
|
|
|
|
|
|
|
|
|
|
@ -141,8 +141,8 @@ func (rp *repoProvider) GetRepoByURL(URL string) (ChartRepo, error) {
|
|
|
|
return rp.createRepoByType(cr)
|
|
|
|
return rp.createRepoByType(cr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (rp *repoProvider) findRepoByURL(URL string) ChartRepo {
|
|
|
|
func (rp *repoProvider) findRepoByURL(URL string) IChartRepo {
|
|
|
|
var found ChartRepo
|
|
|
|
var found IChartRepo
|
|
|
|
for _, r := range rp.repos {
|
|
|
|
for _, r := range rp.repos {
|
|
|
|
rURL := r.GetURL()
|
|
|
|
rURL := r.GetURL()
|
|
|
|
if strings.HasPrefix(URL, rURL) {
|
|
|
|
if strings.HasPrefix(URL, rURL) {
|
|
|
@ -178,17 +178,17 @@ func (rp *repoProvider) GetChartByReference(reference string) (*chart.Chart, err
|
|
|
|
return r.GetChart(name)
|
|
|
|
return r.GetChart(name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GCSRepoProvider is a factory for GCS Repo instances.
|
|
|
|
// GCSRepoProvider is a factory for GCS IRepo instances.
|
|
|
|
type GCSRepoProvider interface {
|
|
|
|
type GCSRepoProvider interface {
|
|
|
|
GetGCSRepo(r Repo) (ObjectStorageRepo, error)
|
|
|
|
GetGCSRepo(r IRepo) (IStorageRepo, error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type gcsRepoProvider struct {
|
|
|
|
type gcsRepoProvider struct {
|
|
|
|
cp CredentialProvider
|
|
|
|
cp ICredentialProvider
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// NewGCSRepoProvider creates a GCSRepoProvider.
|
|
|
|
// NewGCSRepoProvider creates a GCSRepoProvider.
|
|
|
|
func NewGCSRepoProvider(cp CredentialProvider) GCSRepoProvider {
|
|
|
|
func NewGCSRepoProvider(cp ICredentialProvider) GCSRepoProvider {
|
|
|
|
if cp == nil {
|
|
|
|
if cp == nil {
|
|
|
|
cp = NewInmemCredentialProvider()
|
|
|
|
cp = NewInmemCredentialProvider()
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -198,7 +198,7 @@ func NewGCSRepoProvider(cp CredentialProvider) GCSRepoProvider {
|
|
|
|
|
|
|
|
|
|
|
|
// GetGCSRepo returns a new Google Cloud Storage repository. If a credential is specified, it will try to
|
|
|
|
// GetGCSRepo returns a new Google Cloud Storage repository. If a credential is specified, it will try to
|
|
|
|
// fetch it and use it, and if the credential isn't found, it will fall back to an unauthenticated client.
|
|
|
|
// fetch it and use it, and if the credential isn't found, it will fall back to an unauthenticated client.
|
|
|
|
func (gcsrp gcsRepoProvider) GetGCSRepo(r Repo) (ObjectStorageRepo, error) {
|
|
|
|
func (gcsrp gcsRepoProvider) GetGCSRepo(r IRepo) (IStorageRepo, error) {
|
|
|
|
client, err := gcsrp.createGCSClient(r.GetCredentialName())
|
|
|
|
client, err := gcsrp.createGCSClient(r.GetCredentialName())
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|