-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
audit.go
56 lines (49 loc) 路 1.17 KB
/
audit.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
49
50
51
52
53
54
55
56
package audit
import (
"fmt"
"io/ioutil"
"path"
"github.com/zricethezav/gitleaks/v3/manager"
log "github.com/sirupsen/logrus"
)
// Run accepts a manager and begins an audit based on the options/configs set in the manager.
func Run(m *manager.Manager) error {
if m.Opts.OwnerPath != "" {
files, err := ioutil.ReadDir(m.Opts.OwnerPath)
if err != nil {
return err
}
for _, f := range files {
if !f.IsDir() {
continue
}
m.Opts.RepoPath = fmt.Sprintf("%s/%s", m.Opts.OwnerPath, f.Name())
if err := runHelper(NewRepo(m)); err != nil {
log.Warnf("%s is not a git repo, skipping", f.Name())
}
}
return nil
}
return runHelper(NewRepo(m))
}
func runHelper(r *Repo) error {
if r.Manager.Opts.OpenLocal() {
r.Name = path.Base(r.Manager.Opts.RepoPath)
if err := r.Open(); err != nil {
return err
}
// Check if we are checking uncommitted files. This is the default behavior
// for a "$ gitleaks" command with no options set
if r.Manager.Opts.CheckUncommitted() {
if err := r.AuditUncommitted(); err != nil {
return err
}
return nil
}
} else {
if err := r.Clone(nil); err != nil {
return err
}
}
return r.Audit()
}