-
Notifications
You must be signed in to change notification settings - Fork 153
/
repo_entry_v2.go
65 lines (52 loc) · 1.37 KB
/
repo_entry_v2.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
package helmutil
import (
"fmt"
"path/filepath"
"strings"
"github.com/pkg/errors"
"k8s.io/helm/pkg/repo"
)
// RepoEntryV2 implements RepoEntry in Helm v2.
type RepoEntryV2 struct {
entry *repo.Entry
}
func (r RepoEntryV2) Name() string {
return r.entry.Name
}
func (r RepoEntryV2) URL() string {
return r.entry.URL
}
func (r RepoEntryV2) IndexURL() string {
return IndexFileURL(r.entry.URL)
}
func (r RepoEntryV2) CacheFile() string {
cache := r.entry.Cache
if !filepath.IsAbs(cache) {
cache = filepath.Join(cacheDirPathV2(), cache)
}
return cache
}
func lookupV2(name string) (RepoEntryV2, error) {
repoFile, err := helm2LoadRepoFile(repoFilePathV2())
if err != nil {
return RepoEntryV2{}, errors.Wrap(err, "load repo file")
}
if entry, ok := repoFile.Get(name); ok {
return RepoEntryV2{entry: entry}, nil
}
return RepoEntryV2{}, errors.Errorf("repo with name %s not found, try `helm repo add %s <uri>`", name, name)
}
func lookupByURLV2(url string) (RepoEntryV2, bool, error) {
repoFile, err := helm2LoadRepoFile(repoFilePathV2())
if err != nil {
return RepoEntryV2{}, false, fmt.Errorf("load repo file: %v", err)
}
url = strings.TrimSuffix(url, "/")
for _, entry := range repoFile.Repositories {
entryURL := strings.TrimSuffix(entry.URL, "/")
if url == entryURL {
return RepoEntryV2{entry: entry}, true, nil
}
}
return RepoEntryV2{}, false, nil
}