-
Notifications
You must be signed in to change notification settings - Fork 88
/
fetch.go
50 lines (42 loc) · 1.23 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
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 {
HelmRepoName string
HelmRepoURI string
LocalPath string
License *kotsv1beta1.License
}
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.License)
}
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)
}