host.go 851 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package hosts
  2. import (
  3. "github.com/zricethezav/gitleaks/manager"
  4. "strings"
  5. )
  6. const (
  7. _github int = iota + 1
  8. _gitlab
  9. )
  10. // Host is an interface used for defining external git hosting providers like github and gitlab.
  11. // TODO add bitbucket
  12. type Host interface {
  13. Audit()
  14. AuditPR()
  15. }
  16. // Run kicks off a host audit. This function accepts a manager and determines what host it should audit
  17. func Run(m *manager.Manager) error {
  18. var host Host
  19. switch getHost(m.Opts.Host) {
  20. case _github:
  21. host = NewGithubClient(*m)
  22. case _gitlab:
  23. host = NewGitlabClient(*m)
  24. default:
  25. return nil
  26. }
  27. if m.Opts.PullRequest != "" {
  28. host.AuditPR()
  29. } else {
  30. host.Audit()
  31. }
  32. return nil
  33. }
  34. func getHost(host string) int {
  35. if strings.ToLower(host) == "github" {
  36. return _github
  37. } else if strings.ToLower(host) == "gitlab" {
  38. return _gitlab
  39. }
  40. return -1
  41. }