Skip to content

Commit

Permalink
Retry without authentication when upstream REQUIRES authentication an…
Browse files Browse the repository at this point in the history
…d add support for basic auth in CLI
  • Loading branch information
mstg committed Mar 25, 2022
1 parent 08aed87 commit e0081b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions cmd/srpmproc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ var (
manualCommits string
moduleFallbackStream string
allowStreamBranches bool
basicUsername string
basicPassword string
)

var root = &cobra.Command{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions pkg/modes/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit e0081b4

Please sign in to comment.