Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func init() {
flags.StringVarP(&loginConfig.Password, "password", "p", "", "Password for login")
flags.BoolVar(&loginConfig.PasswordStdin, "password-stdin", true, "Take the password from stdin by default")
flags.BoolVar(&loginConfig.PlainHTTP, "plain-http", false, "Allow http connections to registry")
flags.BoolVar(&loginConfig.Insecure, "insecure", false, "Allow insecure connections to registry")

if err := viper.BindPFlags(flags); err != nil {
panic(fmt.Errorf("bind cache login flags to viper: %w", err))
Expand Down
19 changes: 18 additions & 1 deletion pkg/backend/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ package backend

import (
"context"
"crypto/tls"
"net/http"

"github.com/CloudNativeAI/modctl/pkg/config"
"oras.land/oras-go/v2/registry/remote"
"oras.land/oras-go/v2/registry/remote/auth"
"oras.land/oras-go/v2/registry/remote/credentials"
"oras.land/oras-go/v2/registry/remote/retry"

"github.com/CloudNativeAI/modctl/pkg/config"
)

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

httpClient := &http.Client{
Transport: retry.NewTransport(&http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: cfg.Insecure,
},
}),
}
reg.Client = &auth.Client{
Cache: auth.NewCache(),
Credential: credentials.Credential(store),
Client: httpClient,
}

if cfg.PlainHTTP {
reg.PlainHTTP = true
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Login struct {
Password string
PasswordStdin bool
PlainHTTP bool
Insecure bool
}

func NewLogin() *Login {
Expand All @@ -31,6 +32,7 @@ func NewLogin() *Login {
Password: "",
PasswordStdin: true,
PlainHTTP: false,
Insecure: false,
}
}

Expand Down