Added insecure option to login subcommand

Signed-off-by: Andrew Block <andy.block@gmail.com>
pull/11711/head
Andrew Block 3 years ago
parent 08593c8dd6
commit 154f37efec
No known key found for this signature in database
GPG Key ID: 02DFE631AEF35EBC

@ -43,6 +43,7 @@ type registryLoginOptions struct {
certFile string certFile string
keyFile string keyFile string
caFile string caFile string
insecure bool
} }
func newRegistryLoginCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { func newRegistryLoginCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
@ -65,7 +66,8 @@ func newRegistryLoginCmd(cfg *action.Configuration, out io.Writer) *cobra.Comman
return action.NewRegistryLogin(cfg).Run(out, hostname, username, password, return action.NewRegistryLogin(cfg).Run(out, hostname, username, password,
action.WithCertFile(o.certFile), action.WithCertFile(o.certFile),
action.WithKeyFile(o.keyFile), action.WithKeyFile(o.keyFile),
action.WithCAFile(o.caFile)) action.WithCAFile(o.caFile),
action.WithInsecure(o.insecure))
}, },
} }
@ -73,6 +75,7 @@ func newRegistryLoginCmd(cfg *action.Configuration, out io.Writer) *cobra.Comman
f.StringVarP(&o.username, "username", "u", "", "registry username") f.StringVarP(&o.username, "username", "u", "", "registry username")
f.StringVarP(&o.password, "password", "p", "", "registry password or identity token") f.StringVarP(&o.password, "password", "p", "", "registry password or identity token")
f.BoolVarP(&o.passwordFromStdinOpt, "password-stdin", "", false, "read password or identity token from stdin") f.BoolVarP(&o.passwordFromStdinOpt, "password-stdin", "", false, "read password or identity token from stdin")
f.BoolVarP(&o.insecure, "insecure", "", false, "allow connections to TLS registry without certs")
f.StringVar(&o.certFile, "cert-file", "", "identify registry client using this SSL certificate file") f.StringVar(&o.certFile, "cert-file", "", "identify registry client using this SSL certificate file")
f.StringVar(&o.keyFile, "key-file", "", "identify registry client using this SSL key file") f.StringVar(&o.keyFile, "key-file", "", "identify registry client using this SSL key file")
f.StringVar(&o.caFile, "ca-file", "", "verify certificates of HTTPS-enabled servers using this CA bundle") f.StringVar(&o.caFile, "ca-file", "", "verify certificates of HTTPS-enabled servers using this CA bundle")

@ -28,6 +28,7 @@ type RegistryLogin struct {
certFile string certFile string
keyFile string keyFile string
caFile string caFile string
insecure bool
} }
type RegistryLoginOpt func(*RegistryLogin) error type RegistryLoginOpt func(*RegistryLogin) error
@ -40,6 +41,14 @@ func WithCertFile(certFile string) RegistryLoginOpt {
} }
} }
// WithKeyFile specifies whether to very certificates when communicating.
func WithInsecure(insecure bool) RegistryLoginOpt {
return func(r *RegistryLogin) error {
r.insecure = insecure
return nil
}
}
// WithKeyFile specifies the path to the key file to use for TLS. // WithKeyFile specifies the path to the key file to use for TLS.
func WithKeyFile(keyFile string) RegistryLoginOpt { func WithKeyFile(keyFile string) RegistryLoginOpt {
return func(r *RegistryLogin) error { return func(r *RegistryLogin) error {
@ -74,5 +83,6 @@ func (a *RegistryLogin) Run(out io.Writer, hostname string, username string, pas
return a.cfg.RegistryClient.Login( return a.cfg.RegistryClient.Login(
hostname, hostname,
registry.LoginOptBasicAuth(username, password), registry.LoginOptBasicAuth(username, password),
registry.LoginOptInsecure(a.insecure),
registry.LoginOptTLSClientConfig(a.certFile, a.keyFile, a.caFile)) registry.LoginOptTLSClientConfig(a.certFile, a.keyFile, a.caFile))
} }

@ -39,6 +39,7 @@ func TestOCIGetter(t *testing.T) {
ca, pub, priv := join(cd, "rootca.crt"), join(cd, "crt.pem"), join(cd, "key.pem") ca, pub, priv := join(cd, "rootca.crt"), join(cd, "crt.pem"), join(cd, "key.pem")
timeout := time.Second * 5 timeout := time.Second * 5
transport := &http.Transport{} transport := &http.Transport{}
insecureSkipTLSverify := false
// Test with options // Test with options
g, err = NewOCIGetter( g, err = NewOCIGetter(
@ -46,6 +47,7 @@ func TestOCIGetter(t *testing.T) {
WithTLSClientConfig(pub, priv, ca), WithTLSClientConfig(pub, priv, ca),
WithTimeout(timeout), WithTimeout(timeout),
WithTransport(transport), WithTransport(transport),
WithInsecureSkipVerifyTLS(insecureSkipTLSverify),
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

Loading…
Cancel
Save