github.com/argoproj/argo-cd@v1.8.7/util/db/helmrepository.go (about) 1 package db 2 3 import ( 4 "context" 5 "strings" 6 7 "google.golang.org/grpc/codes" 8 "google.golang.org/grpc/status" 9 v1 "k8s.io/api/core/v1" 10 "k8s.io/utils/pointer" 11 12 "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1" 13 "github.com/argoproj/argo-cd/util/settings" 14 ) 15 16 func getHelmRepoCredIndex(helmRepositories []settings.HelmRepoCredentials, repoURL string) int { 17 for i, cred := range helmRepositories { 18 if strings.EqualFold(cred.URL, repoURL) { 19 return i 20 } 21 } 22 return -1 23 } 24 25 func (db *db) getHelmRepo(repoURL string, helmRepositories []settings.HelmRepoCredentials) (*v1alpha1.Repository, error) { 26 index := getHelmRepoCredIndex(helmRepositories, repoURL) 27 if index < 0 { 28 return nil, status.Errorf(codes.NotFound, "repo '%s' not found", repoURL) 29 } 30 repoInfo := helmRepositories[index] 31 32 repo := &v1alpha1.Repository{ 33 Repo: repoInfo.URL, 34 Type: "helm", 35 Name: repoInfo.Name, 36 } 37 err := db.unmarshalFromSecretsStr(map[*string]*v1.SecretKeySelector{ 38 &repo.Username: repoInfo.UsernameSecret, 39 &repo.Password: repoInfo.PasswordSecret, 40 &repo.TLSClientCertData: repoInfo.CertSecret, 41 &repo.TLSClientCertKey: repoInfo.KeySecret, 42 }, make(map[string]*v1.Secret)) 43 return repo, err 44 } 45 46 // ListHelmRepoURLs lists configured helm repositories 47 func (db *db) ListHelmRepositories(ctx context.Context) ([]*v1alpha1.Repository, error) { 48 helmRepositories, err := db.settingsMgr.GetHelmRepositories() 49 if err != nil { 50 return nil, err 51 } 52 53 result := make([]*v1alpha1.Repository, len(helmRepositories)) 54 for i, helmRepoInfo := range helmRepositories { 55 repo, err := db.getHelmRepo(helmRepoInfo.URL, helmRepositories) 56 if err != nil { 57 return nil, err 58 } 59 result[i] = repo 60 } 61 repos, err := db.listRepositories(ctx, pointer.StringPtr("helm")) 62 if err != nil { 63 return nil, err 64 } 65 result = append(result, v1alpha1.Repositories(repos).Filter(func(r *v1alpha1.Repository) bool { 66 return r.Type == "helm" && r.Name != "" 67 })...) 68 return result, nil 69 }