-
Notifications
You must be signed in to change notification settings - Fork 90
/
fetch.go
96 lines (83 loc) · 2.73 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package upstream
import (
"net/url"
"github.com/pkg/errors"
"github.com/replicatedhq/kots/pkg/crypto"
"github.com/replicatedhq/kots/pkg/replicatedapp"
"github.com/replicatedhq/kots/pkg/upstream/types"
"github.com/replicatedhq/kots/pkg/util"
)
func FetchUpstream(upstreamURI string, fetchOptions *types.FetchOptions) (*types.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 *types.FetchOptions) (*types.Upstream, error) {
if !util.IsURL(upstreamURI) {
return readFilesFromPath(upstreamURI)
}
if fetchOptions.EncryptionKey != "" {
err := crypto.InitFromString(fetchOptions.EncryptionKey)
if err != nil {
return nil, errors.Wrap(err, "failed to create cipher")
}
}
u, err := url.ParseRequestURI(upstreamURI)
if err != nil {
return nil, errors.Wrap(err, "parse request uri failed")
}
if u.Scheme == "replicated" {
return downloadReplicated(
u,
fetchOptions.LocalPath,
fetchOptions.RootDir,
fetchOptions.UseAppDir,
fetchOptions.License,
fetchOptions.ConfigValues,
fetchOptions.IdentityConfig,
pickCursor(fetchOptions),
pickVersionLabel(fetchOptions),
pickVersionIsRequired(fetchOptions),
fetchOptions.AppSlug,
fetchOptions.AppSequence,
fetchOptions.Airgap != nil,
fetchOptions.Airgap,
fetchOptions.LocalRegistry,
fetchOptions.ReportingInfo,
fetchOptions.SkipCompatibilityCheck,
)
}
return nil, errors.Errorf("unknown protocol scheme %q", u.Scheme)
}
func pickVersionIsRequired(fetchOptions *types.FetchOptions) bool {
if fetchOptions.Airgap != nil {
return fetchOptions.Airgap.Spec.IsRequired
}
return fetchOptions.CurrentVersionIsRequired
}
func pickVersionLabel(fetchOptions *types.FetchOptions) string {
if fetchOptions.Airgap != nil && fetchOptions.Airgap.Spec.VersionLabel != "" {
return fetchOptions.Airgap.Spec.VersionLabel
}
// only initial install can request a specific version label
if fetchOptions.AppSequence == 0 && fetchOptions.AppVersionLabel != "" {
return fetchOptions.AppVersionLabel
}
return fetchOptions.CurrentVersionLabel
}
func pickCursor(fetchOptions *types.FetchOptions) replicatedapp.ReplicatedCursor {
if fetchOptions.Airgap != nil && fetchOptions.Airgap.Spec.UpdateCursor != "" {
return replicatedapp.ReplicatedCursor{
ChannelID: fetchOptions.Airgap.Spec.ChannelID,
ChannelName: fetchOptions.Airgap.Spec.ChannelName,
Cursor: fetchOptions.Airgap.Spec.UpdateCursor,
}
}
return replicatedapp.ReplicatedCursor{
ChannelID: fetchOptions.CurrentChannelID,
ChannelName: fetchOptions.CurrentChannelName,
Cursor: fetchOptions.CurrentCursor,
}
}