Skip to content

Commit

Permalink
fix: Fall back to anonymous GitHub provider for getting quickstarts
Browse files Browse the repository at this point in the history
Similar problem as #6315 - if there are no GitHub credentials, we
still try to use an authenticated user for listing the quickstarts. So
let's watch for an error creating the git provider for listing
quickstarts from a location, and if that location is a default
location, use an anonymous GitHub provider instead.

fixes #6471

Signed-off-by: Andrew Bayer <[email protected]>
  • Loading branch information
abayer authored and jenkins-x-bot committed Jan 14, 2020
1 parent 773cd99 commit 8d3e125
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/cmd/opts/quickstarts.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,18 @@ func (o *CommonOptions) LoadQuickStartsFromLocations(locations []v1.QuickStartLo
if kind == "" {
kind = gits.KindGitHub
}
gitProvider, err := o.GitProviderForGitServerURL(gitURL, kind, "")

var gitProvider gits.GitProvider
var err error

// If this is a default quickstart location but there's no github.com credentials, fall back to anonymous
server := config.GetOrCreateServer(gitURL)
userAuth := config.CurrentUser(server, o.InCluster())
if kube.IsDefaultQuickstartLocation(location) && (userAuth == nil || userAuth.IsInvalid()) {
gitProvider, err = gits.NewAnonymousGitHubProvider(server, nil)
} else {
gitProvider, err = o.GitProviderForGitServerURL(gitURL, kind, "")
}
if err != nil {
return model, err
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/kube/quickstarts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kube

import (
"fmt"
"reflect"

v1 "github.com/jenkins-x/jx/pkg/apis/jenkins.io/v1"
"github.com/jenkins-x/jx/pkg/client/clientset/versioned"
Expand Down Expand Up @@ -34,3 +35,13 @@ func GetQuickstartLocations(jxClient versioned.Interface, ns string) ([]v1.Quick
answer = env.Spec.TeamSettings.QuickstartLocations
return answer, nil
}

// IsDefaultQuickstartLocation checks whether the given quickstart location is a default one, and if so returns true
func IsDefaultQuickstartLocation(location v1.QuickStartLocation) bool {
for _, l := range DefaultQuickstartLocations {
if reflect.DeepEqual(l, location) {
return true
}
}
return false
}

0 comments on commit 8d3e125

Please sign in to comment.