Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
add support for env proxying when using https with custom CAs
Browse files Browse the repository at this point in the history
Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
  • Loading branch information
aryan9600 committed Nov 23, 2022
1 parent 329fd66 commit c9e9377
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions plumbing/transport/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"net"
gohttp "net/http"
"time"

"github.com/fluxcd/go-git/v5/plumbing/transport"
"github.com/fluxcd/go-git/v5/plumbing/transport/file"
Expand All @@ -24,12 +26,25 @@ var Protocols = map[string]transport.Transport{
"file": file.DefaultClient,
}

var dialer = net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}

func defaultTransport() *gohttp.Transport {
t := gohttp.DefaultTransport.(*gohttp.Transport).Clone()
if t.TLSClientConfig != nil {
t.TLSClientConfig = &tls.Config{}
}
return t
}

var insecureClient = http.NewClient(&gohttp.Client{
Transport: &gohttp.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
Transport: func() *gohttp.Transport {
t := defaultTransport()
t.TLSClientConfig.InsecureSkipVerify = true
return t
}(),
})

// InstallProtocol adds or modifies an existing protocol.
Expand Down Expand Up @@ -62,11 +77,11 @@ func getTransport(endpoint *transport.Endpoint) (transport.Transport, error) {
}
rootCAs.AppendCertsFromPEM(endpoint.CaBundle)
return http.NewClient(&gohttp.Client{
Transport: &gohttp.Transport{
TLSClientConfig: &tls.Config{
RootCAs: rootCAs,
},
},
Transport: func() *gohttp.Transport {
t := defaultTransport()
t.TLSClientConfig.RootCAs = rootCAs
return t
}(),
}), nil
}
}
Expand Down

0 comments on commit c9e9377

Please sign in to comment.