Pass cli configuration around

Signed-off-by: Tom Runyon <tom@defenseunicorns.com>
pull/11623/head
Tom Runyon 3 years ago
parent 1acb7731dc
commit c50cb0c0ae
No known key found for this signature in database
GPG Key ID: D1CF51977E0E790F

@ -78,7 +78,8 @@ func newPushCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
client := action.NewPushWithOpts(action.WithPushConfig(cfg), client := action.NewPushWithOpts(action.WithPushConfig(cfg),
action.WithTLSClientConfig(o.certFile, o.keyFile, o.caFile), action.WithTLSClientConfig(o.certFile, o.keyFile, o.caFile),
action.WithInsecureSkipTLSVerify(o.insecureSkipTLSverify), action.WithInsecureSkipTLSVerify(o.insecureSkipTLSverify),
action.WithPushOptWriter(out)) action.WithPushOptWriter(out),
action.WithPushOptHTTP(o.plainHTTP))
client.Settings = settings client.Settings = settings
output, err := client.Run(chartRef, remote) output, err := client.Run(chartRef, remote)
if err != nil { if err != nil {

@ -109,15 +109,16 @@ func (p *Pull) Run(chartRef string) (string, error) {
if registry.IsOCI(chartRef) { if registry.IsOCI(chartRef) {
// Provide a tls enabled client for the pull command if the user has // Provide a tls enabled client for the pull command if the user has
// specified the cert file or key file or ca file. // specified the cert file or key file or ca file.
if (p.ChartPathOptions.CertFile != "" && p.ChartPathOptions.KeyFile != "") || p.ChartPathOptions.CaFile != "" || p.ChartPathOptions.InsecureSkipTLSverify {
var registryClient *registry.Client
var err error
if p.PlainHTTP { if p.PlainHTTP {
registryClient, err = registry.NewRegistryClientHTTP(p.out, p.Settings.RegistryConfig, p.Settings.Debug) registryClient, err := registry.NewRegistryClientHTTP(p.out, p.Settings.RegistryConfig, p.Settings.Debug)
} else { if err != nil {
registryClient, err = registry.NewRegistryClientWithTLS(p.out, p.CertFile, p.KeyFile, p.CaFile, return out.String(), err
p.InsecureSkipTLSverify, p.Settings.RegistryConfig, p.Settings.Debug) }
p.cfg.RegistryClient = registryClient
} }
if (p.ChartPathOptions.CertFile != "" && p.ChartPathOptions.KeyFile != "") || p.ChartPathOptions.CaFile != "" || p.ChartPathOptions.InsecureSkipTLSverify {
registryClient, err := registry.NewRegistryClientWithTLS(p.out, p.CertFile, p.KeyFile, p.CaFile,
p.InsecureSkipTLSverify, p.Settings.RegistryConfig, p.Settings.Debug)
if err != nil { if err != nil {
return out.String(), err return out.String(), err
} }

@ -73,6 +73,13 @@ func WithPushOptWriter(out io.Writer) PushOpt {
} }
} }
// WithOptWriter sets the registryOut field on the push configuration object.
func WithPushOptHTTP(plainHTTP bool) PushOpt {
return func(p *Push) {
p.plainHTTP = plainHTTP
}
}
// NewPushWithOpts creates a new push, with configuration options. // NewPushWithOpts creates a new push, with configuration options.
func NewPushWithOpts(opts ...PushOpt) *Push { func NewPushWithOpts(opts ...PushOpt) *Push {
p := &Push{} p := &Push{}
@ -92,6 +99,7 @@ func (p *Push) Run(chartRef string, remote string) (string, error) {
Options: []pusher.Option{ Options: []pusher.Option{
pusher.WithTLSClientConfig(p.certFile, p.keyFile, p.caFile), pusher.WithTLSClientConfig(p.certFile, p.keyFile, p.caFile),
pusher.WithInsecureSkipTLSVerify(p.insecureSkipTLSverify), pusher.WithInsecureSkipTLSVerify(p.insecureSkipTLSverify),
pusher.WithPlainHTTP(p.plainHTTP),
}, },
} }

@ -45,6 +45,7 @@ type options struct {
registryClient *registry.Client registryClient *registry.Client
timeout time.Duration timeout time.Duration
transport *http.Transport transport *http.Transport
plainHTTP bool
} }
// Option allows specifying various settings configurable by the user for overriding the defaults // Option allows specifying various settings configurable by the user for overriding the defaults

@ -122,6 +122,14 @@ func (g *OCIGetter) newRegistryClient() (*registry.Client, error) {
} }
}) })
if g.opts.plainHTTP {
registryClient, err := registry.NewClient(registry.ClientOptPlainHTTP(g.opts.plainHTTP))
if err != nil {
return nil, err
}
return registryClient, nil
}
if (g.opts.certFile != "" && g.opts.keyFile != "") || g.opts.caFile != "" || g.opts.insecureSkipVerifyTLS { if (g.opts.certFile != "" && g.opts.keyFile != "") || g.opts.caFile != "" || g.opts.insecureSkipVerifyTLS {
tlsConf, err := tlsutil.NewClientTLS(g.opts.certFile, g.opts.keyFile, g.opts.caFile, g.opts.insecureSkipVerifyTLS) tlsConf, err := tlsutil.NewClientTLS(g.opts.certFile, g.opts.keyFile, g.opts.caFile, g.opts.insecureSkipVerifyTLS)
if err != nil { if err != nil {

@ -106,6 +106,13 @@ func NewOCIPusher(ops ...Option) (Pusher, error) {
} }
func (pusher *OCIPusher) newRegistryClient() (*registry.Client, error) { func (pusher *OCIPusher) newRegistryClient() (*registry.Client, error) {
if pusher.opts.plainHTTP {
registryClient, err := registry.NewClient(registry.ClientOptPlainHTTP(pusher.opts.plainHTTP))
if err != nil {
return nil, err
}
return registryClient, nil
}
if (pusher.opts.certFile != "" && pusher.opts.keyFile != "") || pusher.opts.caFile != "" || pusher.opts.insecureSkipTLSverify { if (pusher.opts.certFile != "" && pusher.opts.keyFile != "") || pusher.opts.caFile != "" || pusher.opts.insecureSkipTLSverify {
tlsConf, err := tlsutil.NewClientTLS(pusher.opts.certFile, pusher.opts.keyFile, pusher.opts.caFile, pusher.opts.insecureSkipTLSverify) tlsConf, err := tlsutil.NewClientTLS(pusher.opts.certFile, pusher.opts.keyFile, pusher.opts.caFile, pusher.opts.insecureSkipTLSverify)
if err != nil { if err != nil {

@ -32,6 +32,7 @@ type options struct {
keyFile string keyFile string
caFile string caFile string
insecureSkipTLSverify bool insecureSkipTLSverify bool
plainHTTP bool
} }
// Option allows specifying various settings configurable by the user for overriding the defaults // Option allows specifying various settings configurable by the user for overriding the defaults
@ -61,6 +62,13 @@ func WithInsecureSkipTLSVerify(insecureSkipTLSVerify bool) Option {
} }
} }
// WithPlainHTTP determines if a connection to registry is done over HTTP
func WithPlainHTTP(plainHTTP bool) Option {
return func(opts *options) {
opts.plainHTTP = plainHTTP
}
}
// Pusher is an interface to support upload to the specified URL. // Pusher is an interface to support upload to the specified URL.
type Pusher interface { type Pusher interface {
// Push file content by url string // Push file content by url string

Loading…
Cancel
Save