Skip to content

Commit

Permalink
fix docs, error handling and managed proxy auth
Browse files Browse the repository at this point in the history
Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
  • Loading branch information
aryan9600 committed May 27, 2022
1 parent b6b00e3 commit 1a32e3c
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 15 deletions.
4 changes: 2 additions & 2 deletions controllers/gitrepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion internal/features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
}
Expand Down
6 changes: 0 additions & 6 deletions pkg/git/libgit2/managed/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,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()
Expand Down
2 changes: 1 addition & 1 deletion pkg/git/libgit2/managed/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 0 additions & 2 deletions pkg/git/libgit2/managed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions pkg/git/strategy/proxy/strategy_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 1a32e3c

Please sign in to comment.