Retry without authentication when upstream REQUIRES authentication and add support for basic auth in CLI

This commit is contained in:
Mustafa Gezen 2022-03-25 18:54:23 +01:00
parent 08aed871a3
commit e0081b4ad9
2 changed files with 9 additions and 3 deletions

View File

@ -51,6 +51,8 @@ var (
manualCommits string
moduleFallbackStream string
allowStreamBranches bool
basicUsername string
basicPassword string
)
var root = &cobra.Command{
@ -82,6 +84,8 @@ func mn(_ *cobra.Command, _ []string) {
NoStorageDownload: noStorageDownload,
SingleTag: singleTag,
CdnUrl: cdnUrl,
HttpUsername: basicUsername,
HttpPassword: basicPassword,
})
if err != nil {
log.Fatal(err)
@ -127,6 +131,8 @@ func main() {
root.Flags().StringVar(&manualCommits, "manual-commits", "", "Comma separated branch and commit list for packages with broken release tags (Format: BRANCH:HASH)")
root.Flags().StringVar(&moduleFallbackStream, "module-fallback-stream", "", "Override fallback stream. Some module packages are published as collections and mostly use the same stream name, some of them deviate from the main stream")
root.Flags().BoolVar(&allowStreamBranches, "allow-stream-branches", false, "Allow import from stream branches")
root.Flags().StringVar(&basicUsername, "basic-username", "", "Basic auth username")
root.Flags().StringVar(&basicPassword, "basic-password", "", "Basic auth password")
if err := root.Execute(); err != nil {
log.Fatal(err)

View File

@ -91,7 +91,7 @@ func (g *GitMode) RetrieveSource(pd *data.ProcessData) (*data.ModeData, error) {
err = remote.Fetch(fetchOpts)
if err != nil {
if err == transport.ErrInvalidAuthMethod {
if err == transport.ErrInvalidAuthMethod || err == transport.ErrAuthenticationRequired {
fetchOpts.Auth = nil
err = remote.Fetch(fetchOpts)
if err != nil {
@ -137,7 +137,7 @@ func (g *GitMode) RetrieveSource(pd *data.ProcessData) (*data.ModeData, error) {
}
list, err := remote.List(listOpts)
if err != nil {
if err == transport.ErrInvalidAuthMethod {
if err == transport.ErrInvalidAuthMethod || err == transport.ErrAuthenticationRequired {
listOpts.Auth = nil
list, err = remote.List(listOpts)
if err != nil {
@ -211,7 +211,7 @@ func (g *GitMode) WriteSource(pd *data.ProcessData, md *data.ModeData) error {
}
err = remote.Fetch(fetchOpts)
if err != nil && err != git.NoErrAlreadyUpToDate {
if err == transport.ErrInvalidAuthMethod {
if err == transport.ErrInvalidAuthMethod || err == transport.ErrAuthenticationRequired {
fetchOpts.Auth = nil
err = remote.Fetch(fetchOpts)
if err != nil && err != git.NoErrAlreadyUpToDate {