...
1
16
17 package pusher
18
19 import (
20 "github.com/pkg/errors"
21
22 "helm.sh/helm/v3/pkg/cli"
23 "helm.sh/helm/v3/pkg/registry"
24 )
25
26
27
28
29 type options struct {
30 registryClient *registry.Client
31 certFile string
32 keyFile string
33 caFile string
34 insecureSkipTLSverify bool
35 plainHTTP bool
36 }
37
38
39
40 type Option func(*options)
41
42
43 func WithRegistryClient(client *registry.Client) Option {
44 return func(opts *options) {
45 opts.registryClient = client
46 }
47 }
48
49
50 func WithTLSClientConfig(certFile, keyFile, caFile string) Option {
51 return func(opts *options) {
52 opts.certFile = certFile
53 opts.keyFile = keyFile
54 opts.caFile = caFile
55 }
56 }
57
58
59 func WithInsecureSkipTLSVerify(insecureSkipTLSVerify bool) Option {
60 return func(opts *options) {
61 opts.insecureSkipTLSverify = insecureSkipTLSVerify
62 }
63 }
64
65 func WithPlainHTTP(plainHTTP bool) Option {
66 return func(opts *options) {
67 opts.plainHTTP = plainHTTP
68 }
69 }
70
71
72 type Pusher interface {
73
74 Push(chartRef, url string, options ...Option) error
75 }
76
77
78
79 type Constructor func(options ...Option) (Pusher, error)
80
81
82 type Provider struct {
83 Schemes []string
84 New Constructor
85 }
86
87
88 func (p Provider) Provides(scheme string) bool {
89 for _, i := range p.Schemes {
90 if i == scheme {
91 return true
92 }
93 }
94 return false
95 }
96
97
98 type Providers []Provider
99
100
101
102
103 func (p Providers) ByScheme(scheme string) (Pusher, error) {
104 for _, pp := range p {
105 if pp.Provides(scheme) {
106 return pp.New()
107 }
108 }
109 return nil, errors.Errorf("scheme %q not supported", scheme)
110 }
111
112 var ociProvider = Provider{
113 Schemes: []string{registry.OCIScheme},
114 New: NewOCIPusher,
115 }
116
117
118
119 func All(_ *cli.EnvSettings) Providers {
120 result := Providers{ociProvider}
121 return result
122 }
123
View as plain text