Return errors for failed host clients

This commit is contained in:
Peter Gallagher committed 2019-12-05 12:11:46 +00:00
1 parent c5e1e8abc0
commit f89b8f2b29
3 files changed
+11 -8

No files matched your search

+3 -3
View File
@@ -27,7 +27,8 @@ type Github struct {
// NewGithubClient accepts a manager struct and returns a Github host pointer which will be used to // 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. // 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() ctx := context.Background()
token := oauth2.StaticTokenSource( token := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: options.GetAccessToken(m.Opts)}, &oauth2.Token{AccessToken: options.GetAccessToken(m.Opts)},
@@ -39,7 +40,6 @@ func NewGithubClient(m manager.Manager) *Github {
if m.Opts.BaseURL == "" { if m.Opts.BaseURL == "" {
githubClient = github.NewClient(httpClient) githubClient = github.NewClient(httpClient)
} else { } else {
var err error
githubClient, err = github.NewEnterpriseClient(m.Opts.BaseURL, m.Opts.BaseURL, httpClient) githubClient, err = github.NewEnterpriseClient(m.Opts.BaseURL, m.Opts.BaseURL, httpClient)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
@@ -49,7 +49,7 @@ func NewGithubClient(m manager.Manager) *Github {
return &Github{ return &Github{
manager: m, manager: m,
client: githubClient, client: githubClient,
} }, err
} }
// Audit will audit a github user or organization's repos. // Audit will audit a github user or organization's repos.
+4 -2
View File
@@ -22,7 +22,9 @@ type Gitlab struct {
// NewGitlabClient accepts a manager struct and returns a Gitlab host pointer which will be used to // 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. // 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{ gitlabClient := &Gitlab{
manager: m, manager: m,
ctx: context.Background(), 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. // Audit will audit a github user or organization's repos.
+4 -3
View File
@@ -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 // Run kicks off a host audit. This function accepts a manager and determines what host it should audit
func Run(m *manager.Manager) error { func Run(m *manager.Manager) error {
var host Host var host Host
var err error
switch getHost(m.Opts.Host) { switch getHost(m.Opts.Host) {
case _github: case _github:
host = NewGithubClient(*m) host, err = NewGithubClient(*m)
case _gitlab: case _gitlab:
host = NewGitlabClient(*m) host, err = NewGitlabClient(*m)
default: default:
return nil return nil
} }
@@ -34,7 +35,7 @@ func Run(m *manager.Manager) error {
} else { } else {
host.Audit() host.Audit()
} }
return nil return err
} }
func getHost(host string) int { func getHost(host string) int {