...
1
16
17 package action
18
19 import (
20 "io"
21 "strings"
22
23 "helm.sh/helm/v3/pkg/cli"
24 "helm.sh/helm/v3/pkg/pusher"
25 "helm.sh/helm/v3/pkg/registry"
26 "helm.sh/helm/v3/pkg/uploader"
27 )
28
29
30
31
32 type Push struct {
33 Settings *cli.EnvSettings
34 cfg *Configuration
35 certFile string
36 keyFile string
37 caFile string
38 insecureSkipTLSverify bool
39 plainHTTP bool
40 out io.Writer
41 }
42
43
44 type PushOpt func(*Push)
45
46
47 func WithPushConfig(cfg *Configuration) PushOpt {
48 return func(p *Push) {
49 p.cfg = cfg
50 }
51 }
52
53
54 func WithTLSClientConfig(certFile, keyFile, caFile string) PushOpt {
55 return func(p *Push) {
56 p.certFile = certFile
57 p.keyFile = keyFile
58 p.caFile = caFile
59 }
60 }
61
62
63 func WithInsecureSkipTLSVerify(insecureSkipTLSVerify bool) PushOpt {
64 return func(p *Push) {
65 p.insecureSkipTLSverify = insecureSkipTLSVerify
66 }
67 }
68
69
70 func WithPlainHTTP(plainHTTP bool) PushOpt {
71 return func(p *Push) {
72 p.plainHTTP = plainHTTP
73 }
74 }
75
76
77 func WithPushOptWriter(out io.Writer) PushOpt {
78 return func(p *Push) {
79 p.out = out
80 }
81 }
82
83
84 func NewPushWithOpts(opts ...PushOpt) *Push {
85 p := &Push{}
86 for _, fn := range opts {
87 fn(p)
88 }
89 return p
90 }
91
92
93 func (p *Push) Run(chartRef string, remote string) (string, error) {
94 var out strings.Builder
95
96 c := uploader.ChartUploader{
97 Out: &out,
98 Pushers: pusher.All(p.Settings),
99 Options: []pusher.Option{
100 pusher.WithTLSClientConfig(p.certFile, p.keyFile, p.caFile),
101 pusher.WithInsecureSkipTLSVerify(p.insecureSkipTLSverify),
102 pusher.WithPlainHTTP(p.plainHTTP),
103 },
104 }
105
106 if registry.IsOCI(remote) {
107
108 c.Options = append(c.Options, pusher.WithRegistryClient(p.cfg.RegistryClient))
109 }
110
111 return out.String(), c.UploadTo(chartRef, remote)
112 }
113
View as plain text