Skip to content

Commit

Permalink
Merge pull request #232 from blackducksoftware/host-warnings
Browse files Browse the repository at this point in the history
look for likely mistakes with hub hosts, and report
  • Loading branch information
msenmurugan authored Dec 12, 2018
2 parents cbf2868 + aa6a78b commit d65fca6
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/core/hubmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ package core

import (
"fmt"
"regexp"
"time"

"github.com/blackducksoftware/hub-client-go/hubclient"
"github.com/blackducksoftware/perceptor/pkg/hub"
log "github.com/sirupsen/logrus"
)

var commonMistakesRegex = regexp.MustCompile("(http|://|:\\d+)")

type hubClientCreator func(host string) (*hub.Hub, error)

func createMockHubClient(hubURL string) (*hub.Hub, error) {
Expand All @@ -39,6 +42,10 @@ func createMockHubClient(hubURL string) (*hub.Hub, error) {

func createHubClient(username string, password string, port int, httpTimeout time.Duration) hubClientCreator {
return func(host string) (*hub.Hub, error) {
potentialProblems := commonMistakesRegex.FindAllString(host, -1)
if len(potentialProblems) > 0 {
log.Warnf("Hub host %s may be invalid, potential problems are: %s", host, potentialProblems)
}
baseURL := fmt.Sprintf("https://%s:%d", host, port)
rawClient, err := hubclient.NewWithSession(baseURL, hubclient.HubClientDebugTimings, httpTimeout)
if err != nil {
Expand Down

0 comments on commit d65fca6

Please sign in to comment.