Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log warning if unable to resolve GitLab hostname. #359

Merged
merged 1 commit into from
Nov 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"flag"
"fmt"
"log"
"net"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -138,6 +139,7 @@ type WebhookConfig struct {
// its dependencies an error will be returned. This is like the main() function
// for the server CLI command because it injects all the dependencies.
func NewServer(userConfig UserConfig, config Config) (*Server, error) {
logger := logging.NewSimpleLogger("server", nil, false, logging.ToLogLevel(userConfig.LogLevel))
var supportedVCSHosts []models.VCSHostType
var githubClient *vcs.GithubClient
var gitlabClient *vcs.GitlabClient
Expand All @@ -161,12 +163,23 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) {
// Check if they've also provided a scheme so we don't prepend it
// again.
scheme := "https"
hostname := userConfig.GitlabHostname
schemeSplit := strings.Split(userConfig.GitlabHostname, "://")
if len(schemeSplit) > 1 {
scheme = schemeSplit[0]
userConfig.GitlabHostname = schemeSplit[1]
hostname = schemeSplit[1]
}

// Warn if this hostname isn't resolvable. The GitLab client
// doesn't give good error messages in this case.
ips, err := net.LookupIP(hostname)
if err != nil {
logger.Warn("unable to resolve %q: %s", hostname, err)
} else if len(ips) == 0 {
logger.Warn("found no IPs while resolving %q", hostname)
}
apiURL := fmt.Sprintf("%s://%s/api/v4/", scheme, userConfig.GitlabHostname)

apiURL := fmt.Sprintf("%s://%s/api/v4/", scheme, hostname)
if err := gitlabClient.Client.SetBaseURL(apiURL); err != nil {
return nil, errors.Wrapf(err, "setting GitLab API URL: %s", apiURL)
}
Expand Down Expand Up @@ -248,7 +261,6 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) {
Locker: lockingClient,
WorkingDir: workingDir,
}
logger := logging.NewSimpleLogger("server", nil, false, logging.ToLogLevel(userConfig.LogLevel))
eventParser := &events.EventParser{
GithubUser: userConfig.GithubUser,
GithubToken: userConfig.GithubToken,
Expand Down