From 1073b0269afd3e5468cfcc2ad2cc072e2fddac22 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 4 May 2023 17:08:18 +0200 Subject: [PATCH] cli/context/docker: rename receiver for Endpoint Code in methods of this type also used the Client, and having this receiver named "c" made it easy to confuse it for referring to Client ("c"). Signed-off-by: Sebastiaan van Stijn --- cli/context/docker/load.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/cli/context/docker/load.go b/cli/context/docker/load.go index 76f6eaf305..77baa15173 100644 --- a/cli/context/docker/load.go +++ b/cli/context/docker/load.go @@ -40,23 +40,23 @@ func WithTLSData(s store.Reader, contextName string, m EndpointMeta) (Endpoint, } // tlsConfig extracts a context docker endpoint TLS config -func (c *Endpoint) tlsConfig() (*tls.Config, error) { - if c.TLSData == nil && !c.SkipTLSVerify { +func (ep *Endpoint) tlsConfig() (*tls.Config, error) { + if ep.TLSData == nil && !ep.SkipTLSVerify { // there is no specific tls config return nil, nil } var tlsOpts []func(*tls.Config) - if c.TLSData != nil && c.TLSData.CA != nil { + if ep.TLSData != nil && ep.TLSData.CA != nil { certPool := x509.NewCertPool() - if !certPool.AppendCertsFromPEM(c.TLSData.CA) { + if !certPool.AppendCertsFromPEM(ep.TLSData.CA) { return nil, errors.New("failed to retrieve context tls info: ca.pem seems invalid") } tlsOpts = append(tlsOpts, func(cfg *tls.Config) { cfg.RootCAs = certPool }) } - if c.TLSData != nil && c.TLSData.Key != nil && c.TLSData.Cert != nil { - keyBytes := c.TLSData.Key + if ep.TLSData != nil && ep.TLSData.Key != nil && ep.TLSData.Cert != nil { + keyBytes := ep.TLSData.Key pemBlock, _ := pem.Decode(keyBytes) if pemBlock == nil { return nil, errors.New("no valid private key found") @@ -65,7 +65,7 @@ func (c *Endpoint) tlsConfig() (*tls.Config, error) { return nil, errors.New("private key is encrypted - support for encrypted private keys has been removed, see https://docs.docker.com/go/deprecated/") } - x509cert, err := tls.X509KeyPair(c.TLSData.Cert, keyBytes) + x509cert, err := tls.X509KeyPair(ep.TLSData.Cert, keyBytes) if err != nil { return nil, errors.Wrap(err, "failed to retrieve context tls info") } @@ -73,7 +73,7 @@ func (c *Endpoint) tlsConfig() (*tls.Config, error) { cfg.Certificates = []tls.Certificate{x509cert} }) } - if c.SkipTLSVerify { + if ep.SkipTLSVerify { tlsOpts = append(tlsOpts, func(cfg *tls.Config) { cfg.InsecureSkipVerify = true }) @@ -82,21 +82,21 @@ func (c *Endpoint) tlsConfig() (*tls.Config, error) { } // ClientOpts returns a slice of Client options to configure an API client with this endpoint -func (c *Endpoint) ClientOpts() ([]client.Opt, error) { +func (ep *Endpoint) ClientOpts() ([]client.Opt, error) { var result []client.Opt - if c.Host != "" { - helper, err := connhelper.GetConnectionHelper(c.Host) + if ep.Host != "" { + helper, err := connhelper.GetConnectionHelper(ep.Host) if err != nil { return nil, err } if helper == nil { - tlsConfig, err := c.tlsConfig() + tlsConfig, err := ep.tlsConfig() if err != nil { return nil, err } result = append(result, withHTTPClient(tlsConfig), - client.WithHost(c.Host), + client.WithHost(ep.Host), ) } else {