Skip to content

Commit 5a5ed89

Browse files
authored
feat: add --insecure for login command to skip tls verify (#139)
Signed-off-by: chlins <[email protected]>
1 parent da51512 commit 5a5ed89

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

cmd/login.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func init() {
6363
flags.StringVarP(&loginConfig.Password, "password", "p", "", "Password for login")
6464
flags.BoolVar(&loginConfig.PasswordStdin, "password-stdin", true, "Take the password from stdin by default")
6565
flags.BoolVar(&loginConfig.PlainHTTP, "plain-http", false, "Allow http connections to registry")
66+
flags.BoolVar(&loginConfig.Insecure, "insecure", false, "Allow insecure connections to registry")
6667

6768
if err := viper.BindPFlags(flags); err != nil {
6869
panic(fmt.Errorf("bind cache login flags to viper: %w", err))

pkg/backend/login.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ package backend
1818

1919
import (
2020
"context"
21+
"crypto/tls"
22+
"net/http"
2123

22-
"github.com/CloudNativeAI/modctl/pkg/config"
2324
"oras.land/oras-go/v2/registry/remote"
2425
"oras.land/oras-go/v2/registry/remote/auth"
2526
"oras.land/oras-go/v2/registry/remote/credentials"
27+
"oras.land/oras-go/v2/registry/remote/retry"
28+
29+
"github.com/CloudNativeAI/modctl/pkg/config"
2630
)
2731

2832
// Login logs into a registry.
@@ -38,6 +42,19 @@ func (b *backend) Login(ctx context.Context, registry, username, password string
3842
return err
3943
}
4044

45+
httpClient := &http.Client{
46+
Transport: retry.NewTransport(&http.Transport{
47+
TLSClientConfig: &tls.Config{
48+
InsecureSkipVerify: cfg.Insecure,
49+
},
50+
}),
51+
}
52+
reg.Client = &auth.Client{
53+
Cache: auth.NewCache(),
54+
Credential: credentials.Credential(store),
55+
Client: httpClient,
56+
}
57+
4158
if cfg.PlainHTTP {
4259
reg.PlainHTTP = true
4360
}

pkg/config/login.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type Login struct {
2323
Password string
2424
PasswordStdin bool
2525
PlainHTTP bool
26+
Insecure bool
2627
}
2728

2829
func NewLogin() *Login {
@@ -31,6 +32,7 @@ func NewLogin() *Login {
3132
Password: "",
3233
PasswordStdin: true,
3334
PlainHTTP: false,
35+
Insecure: false,
3436
}
3537
}
3638

0 commit comments

Comments
 (0)