/
host.go
48 lines (42 loc) 路 877 Bytes
/
host.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package hosts
import (
"github.com/zricethezav/gitleaks/v3/manager"
"strings"
)
const (
_github int = iota + 1
_gitlab
)
// Host is an interface used for defining external git hosting providers like github and gitlab.
// TODO add bitbucket
type Host interface {
Audit()
AuditPR()
}
// 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, err = NewGithubClient(m)
case _gitlab:
host, err = NewGitlabClient(m)
default:
return nil
}
if m.Opts.PullRequest != "" {
host.AuditPR()
} else {
host.Audit()
}
return err
}
func getHost(host string) int {
if strings.ToLower(host) == "github" {
return _github
} else if strings.ToLower(host) == "gitlab" {
return _gitlab
}
return -1
}