diff --git a/hosts/github.go b/hosts/github.go index 1e14b263..ef6d0a4d 100644 --- a/hosts/github.go +++ b/hosts/github.go @@ -27,7 +27,8 @@ type Github struct { // NewGithubClient accepts a manager struct and returns a Github host pointer which will be used to // perform a github audit on an organization, user, or PR. -func NewGithubClient(m manager.Manager) *Github { +func NewGithubClient(m manager.Manager) (*Github, error) { + var err error ctx := context.Background() token := oauth2.StaticTokenSource( &oauth2.Token{AccessToken: options.GetAccessToken(m.Opts)}, @@ -39,7 +40,6 @@ func NewGithubClient(m manager.Manager) *Github { if m.Opts.BaseURL == "" { githubClient = github.NewClient(httpClient) } else { - var err error githubClient, err = github.NewEnterpriseClient(m.Opts.BaseURL, m.Opts.BaseURL, httpClient) if err != nil { log.Error(err) @@ -49,7 +49,7 @@ func NewGithubClient(m manager.Manager) *Github { return &Github{ manager: m, client: githubClient, - } + }, err } // Audit will audit a github user or organization's repos. diff --git a/hosts/gitlab.go b/hosts/gitlab.go index ab528a79..d1da52fc 100644 --- a/hosts/gitlab.go +++ b/hosts/gitlab.go @@ -22,7 +22,9 @@ type Gitlab struct { // NewGitlabClient accepts a manager struct and returns a Gitlab host pointer which will be used to // perform a gitlab audit on an group or user. -func NewGitlabClient(m manager.Manager) *Gitlab { +func NewGitlabClient(m manager.Manager) (*Gitlab, error) { + var err error + gitlabClient := &Gitlab{ manager: m, ctx: context.Background(), @@ -36,7 +38,7 @@ func NewGitlabClient(m manager.Manager) *Gitlab { } } - return gitlabClient + return gitlabClient, err } // Audit will audit a github user or organization's repos. diff --git a/hosts/host.go b/hosts/host.go index 62aa2d26..866a0171 100644 --- a/hosts/host.go +++ b/hosts/host.go @@ -20,11 +20,12 @@ type Host interface { // Run kicks off a host audit. This function accepts a manager and determines what host it should audit func Run(m *manager.Manager) error { var host Host + var err error switch getHost(m.Opts.Host) { case _github: - host = NewGithubClient(*m) + host, err = NewGithubClient(*m) case _gitlab: - host = NewGitlabClient(*m) + host, err = NewGitlabClient(*m) default: return nil } @@ -34,7 +35,7 @@ func Run(m *manager.Manager) error { } else { host.Audit() } - return nil + return err } func getHost(host string) int {