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