host.go 877 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package hosts
  2. import (
  3. "github.com/zricethezav/gitleaks/v4/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. var err error
  20. switch getHost(m.Opts.Host) {
  21. case _github:
  22. host, err = NewGithubClient(m)
  23. case _gitlab:
  24. host, err = NewGitlabClient(m)
  25. default:
  26. return nil
  27. }
  28. if m.Opts.PullRequest != "" {
  29. host.AuditPR()
  30. } else {
  31. host.Audit()
  32. }
  33. return err
  34. }
  35. func getHost(host string) int {
  36. if strings.ToLower(host) == "github" {
  37. return _github
  38. } else if strings.ToLower(host) == "gitlab" {
  39. return _gitlab
  40. }
  41. return -1
  42. }