Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for proxies #512

Merged
merged 5 commits into from
Oct 15, 2024
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
2 changes: 2 additions & 0 deletions pkg/cmd/options/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type NetworkOptions struct {
ClientCertPath string
ClientCertKeyPath string
Concurrency int
Proxy string
}

func (o *NetworkOptions) AddNetworkFlags(cmd *cobra.Command) {
Expand All @@ -45,6 +46,7 @@ func (o *NetworkOptions) AddNetworkFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(&o.ClientCertKeyPath, "key", "",
fmt.Sprintf("Path to client certificate key used for authentication (can also be set via environment variable %s)", constants.ClientCertKeyEnvVar))
cmd.Flags().IntVar(&o.Concurrency, "concurrency", 5, "Maximum number of simultaneous uploads/downloads")
cmd.Flags().StringVar(&o.Proxy, "proxy", "", "Proxy to use for connections (overrides proxy set by environment)")
}

func (o *NetworkOptions) Complete(ctx context.Context, args []string) error {
Expand Down
8 changes: 8 additions & 0 deletions pkg/lib/network/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"crypto/tls"
"fmt"
"net/http"
"net/url"

"kitops/pkg/cmd/options"
"kitops/pkg/lib/constants"
Expand Down Expand Up @@ -53,6 +54,13 @@ func ClientWithAuth(store credentials.Store, opts *options.NetworkOptions) (*aut
func DefaultClient(opts *options.NetworkOptions) (*auth.Client, error) {
transport := http.DefaultTransport.(*http.Transport).Clone()
transport.TLSClientConfig.InsecureSkipVerify = !opts.TLSVerify
if opts.Proxy != "" {
proxyURL, err := url.Parse(opts.Proxy)
if err != nil {
return nil, fmt.Errorf("invalid proxy URL: %w", err)
}
transport.Proxy = http.ProxyURL(proxyURL)
}
if opts.ClientCertKeyPath != "" && opts.ClientCertPath != "" {
cert, err := tls.LoadX509KeyPair(opts.ClientCertPath, opts.ClientCertKeyPath)
if err != nil {
Expand Down