Enforce effective URL on error messages
Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
This commit is contained in:
parent
d1a7e5d609
commit
43661dd15e
|
|
@ -31,6 +31,7 @@ import (
|
|||
"github.com/fluxcd/pkg/version"
|
||||
|
||||
"github.com/fluxcd/source-controller/pkg/git"
|
||||
"github.com/fluxcd/source-controller/pkg/git/libgit2/managed"
|
||||
)
|
||||
|
||||
// CheckoutStrategyForOptions returns the git.CheckoutStrategy for the given
|
||||
|
|
@ -72,7 +73,7 @@ func (c *CheckoutBranch) Checkout(ctx context.Context, path, url string, opts *g
|
|||
CheckoutBranch: c.Branch,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to clone '%s': %w", url, gitutil.LibGit2Error(err))
|
||||
return nil, fmt.Errorf("unable to clone '%s': %w", managed.EffectiveURL(url), gitutil.LibGit2Error(err))
|
||||
}
|
||||
defer repo.Free()
|
||||
head, err := repo.Head()
|
||||
|
|
@ -101,7 +102,7 @@ func (c *CheckoutTag) Checkout(ctx context.Context, path, url string, opts *git.
|
|||
},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to clone '%s': %w", url, gitutil.LibGit2Error(err))
|
||||
return nil, fmt.Errorf("unable to clone '%s': %w", managed.EffectiveURL(url), gitutil.LibGit2Error(err))
|
||||
}
|
||||
defer repo.Free()
|
||||
cc, err := checkoutDetachedDwim(repo, c.Tag)
|
||||
|
|
@ -125,7 +126,7 @@ func (c *CheckoutCommit) Checkout(ctx context.Context, path, url string, opts *g
|
|||
},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to clone '%s': %w", url, gitutil.LibGit2Error(err))
|
||||
return nil, fmt.Errorf("unable to clone '%s': %w", managed.EffectiveURL(url), gitutil.LibGit2Error(err))
|
||||
}
|
||||
defer repo.Free()
|
||||
oid, err := git2go.NewOid(c.Commit)
|
||||
|
|
@ -157,7 +158,7 @@ func (c *CheckoutSemVer) Checkout(ctx context.Context, path, url string, opts *g
|
|||
},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to clone '%s': %w", url, gitutil.LibGit2Error(err))
|
||||
return nil, fmt.Errorf("unable to clone '%s': %w", managed.EffectiveURL(url), gitutil.LibGit2Error(err))
|
||||
}
|
||||
defer repo.Free()
|
||||
|
||||
|
|
|
|||
|
|
@ -54,3 +54,22 @@ func transportOptions(targetUrl string) (*TransportOptions, bool) {
|
|||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// EffectiveURL returns the effective URL for requests.
|
||||
//
|
||||
// Given that TransportOptions can allow for the target URL to be overriden
|
||||
// this returns the same input if Managed Transport is disabled or if no TargetURL
|
||||
// is set on TransportOptions.
|
||||
func EffectiveURL(targetUrl string) string {
|
||||
if !Enabled() {
|
||||
return targetUrl
|
||||
}
|
||||
|
||||
if opts, found := transportOptions(targetUrl); found {
|
||||
if opts.TargetURL != "" {
|
||||
return opts.TargetURL
|
||||
}
|
||||
}
|
||||
|
||||
return targetUrl
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue