fix docs, error handling and managed proxy auth

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
This commit is contained in:
Sanskar Jaiswal 2022-05-27 11:35:09 +05:30
parent ec45a612b1
commit 972d1cac2a
7 changed files with 7 additions and 22 deletions

View File

@ -735,7 +735,7 @@ func (r *GitRepositoryReconciler) gitCheckout(ctx context.Context,
// managed GIT transport only affects the libgit2 implementation
if managed.Enabled() && obj.Spec.GitImplementation == sourcev1.LibGit2Implementation {
// We set the TransportOptionsURL of this set of authentication options here by constructing
// a unique ID that won't clash in a multi tenant environment. This unique ID is used by
// a unique URL that won't clash in a multi tenant environment. This unique URL is used by
// libgit2 managed transports. This enables us to bypass the inbuilt credentials callback in
// libgit2, which is inflexible and unstable.
if strings.HasPrefix(obj.Spec.URL, "http") {
@ -745,7 +745,7 @@ func (r *GitRepositoryReconciler) gitCheckout(ctx context.Context,
} else {
e := &serror.Stalling{
Err: fmt.Errorf("git repository URL has invalid transport type: '%s'", obj.Spec.URL),
Reason: sourcev1.GitOperationFailedReason,
Reason: sourcev1.URLInvalidReason,
}
return nil, e
}

View File

@ -67,7 +67,7 @@ func Enabled(feature string) (bool, error) {
}
// Disable disables the specified feature. If the feature is not
// present, it's a no-op
// present, it's a no-op.
func Disable(feature string) {
if _, ok := features[feature]; ok {
features[feature] = false

View File

@ -316,7 +316,7 @@ func main() {
if optimize, _ := feathelper.Enabled(features.OptimizedGitClones); optimize {
features.Disable(features.OptimizedGitClones)
setupLog.Info(
"disabling optimzied git clones; git clones can only be optimized when using managed transort",
"disabling optimized git clones; git clones can only be optimized when using managed transport",
)
}
}

View File

@ -47,7 +47,6 @@ import (
"bytes"
"crypto/tls"
"crypto/x509"
"encoding/base64"
"errors"
"fmt"
"io"
@ -212,12 +211,6 @@ func createClientRequest(targetURL string, action git2go.SmartServiceAction,
if authOpts != nil {
if len(authOpts.Username) > 0 {
req.SetBasicAuth(authOpts.Username, authOpts.Password)
if t.Proxy != nil {
t.ProxyConnectHeader.Set(
"Authorization",
"Basic "+basicAuth(authOpts.Username, authOpts.Password),
)
}
}
if len(authOpts.CAFile) > 0 {
certPool := x509.NewCertPool()
@ -413,9 +406,3 @@ func (self *httpSmartSubtransportStream) sendRequest() error {
self.sentRequest = true
return nil
}
// From: https://github.com/golang/go/blob/go1.18/src/net/http/client.go#L418
func basicAuth(username, password string) string {
auth := username + ":" + password
return base64.StdEncoding.EncodeToString([]byte(auth))
}

View File

@ -32,7 +32,7 @@ type TransportOptions struct {
}
var (
// transportOpts maps a unique url to a set of transport options.
// transportOpts maps a unique URL to a set of transport options.
transportOpts = make(map[string]TransportOptions, 0)
m sync.RWMutex
)

View File

@ -472,8 +472,6 @@ func Test_ManagedHTTPCheckout(t *testing.T) {
g.Expect(err).ToNot(HaveOccurred())
defer server.StopHTTP()
// Force managed transport to be enabled
repoPath := "test.git"
err = server.InitRepo("../testdata/git/repo", git.DefaultBranch, repoPath)
g.Expect(err).ToNot(HaveOccurred())

View File

@ -320,10 +320,10 @@ func TestCheckoutStrategyForImplementation_Proxied(t *testing.T) {
defer proxyServer.Close()
// Set the proxy env vars for both HTTP and HTTPS because go-git caches them.
os.Setenv("HTTPS_PROXY", fmt.Sprintf("http://%s", proxyAddr))
os.Setenv("HTTPS_PROXY", fmt.Sprintf("http://smth:else@%s", proxyAddr))
defer os.Unsetenv("HTTPS_PROXY")
os.Setenv("HTTP_PROXY", fmt.Sprintf("http://%s", proxyAddr))
os.Setenv("HTTP_PROXY", fmt.Sprintf("http://smth:else@%s", proxyAddr))
defer os.Unsetenv("HTTP_PROXY")
os.Setenv("NO_PROXY", "*.0.2.1")