-
Notifications
You must be signed in to change notification settings - Fork 90
/
fetch.go
64 lines (55 loc) · 1.84 KB
/
fetch.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
package upstream
import (
"net/url"
"github.com/pkg/errors"
kotsv1beta1 "github.com/replicatedhq/kots/kotskinds/apis/kots/v1beta1"
"github.com/replicatedhq/kots/pkg/util"
)
type FetchOptions struct {
RootDir string
UseAppDir bool
HelmRepoName string
HelmRepoURI string
HelmOptions []string
LocalPath string
License *kotsv1beta1.License
ConfigValues *kotsv1beta1.ConfigValues
Airgap *kotsv1beta1.Airgap
CurrentCursor string
CurrentVersionLabel string
}
func FetchUpstream(upstreamURI string, fetchOptions *FetchOptions) (*Upstream, error) {
upstream, err := downloadUpstream(upstreamURI, fetchOptions)
if err != nil {
return nil, errors.Wrap(err, "download upstream failed")
}
return upstream, nil
}
func downloadUpstream(upstreamURI string, fetchOptions *FetchOptions) (*Upstream, error) {
if !util.IsURL(upstreamURI) {
return readFilesFromPath(upstreamURI)
}
u, err := url.ParseRequestURI(upstreamURI)
if err != nil {
return nil, errors.Wrap(err, "parse request uri failed")
}
if u.Scheme == "helm" {
return downloadHelm(u, fetchOptions.HelmRepoURI)
}
if u.Scheme == "replicated" {
return downloadReplicated(u, fetchOptions.LocalPath, fetchOptions.RootDir, fetchOptions.UseAppDir, fetchOptions.License, fetchOptions.ConfigValues, fetchOptions.CurrentCursor, pickVersionLabel(fetchOptions))
}
if u.Scheme == "git" {
return downloadGit(upstreamURI)
}
if u.Scheme == "http" || u.Scheme == "https" {
return downloadHttp(upstreamURI)
}
return nil, errors.Errorf("unknown protocol scheme %q", u.Scheme)
}
func pickVersionLabel(fetchOptions *FetchOptions) string {
if fetchOptions.Airgap != nil && fetchOptions.Airgap.Spec.VersionLabel != "" {
return fetchOptions.Airgap.Spec.VersionLabel
}
return fetchOptions.CurrentVersionLabel
}