opts guard and removing severity

This commit is contained in:
zach rice committed 2019-11-12 15:18:13 -05:00
1 parent e446ba0738
commit 315ee56024
17 files changed
+99 -121

No files matched your search

+2
View File
@@ -19,6 +19,8 @@ test-integration:
go test github.com/zricethezav/gitleaks/hosts -v -integration
build:
go fmt ./...
golint ./...
go mod tidy
go build $(LDFLAGS)
+1 -3
View File
@@ -20,7 +20,6 @@ func Run(m *manager.Manager) error {
}
m.Opts.RepoPath = fmt.Sprintf("%s/%s", m.Opts.OwnerPath, f.Name())
if err := runHelper(NewRepo(m)); err != nil {
// TODO or send to errchan?
return err
}
}
@@ -31,7 +30,6 @@ func Run(m *manager.Manager) error {
}
func runHelper(r *Repo) error {
// Check if gitleaks will perform a local audit.
if r.Manager.Opts.OpenLocal() {
r.Name = path.Base(r.Manager.Opts.RepoPath)
if err := r.Open(); err != nil {
@@ -41,7 +39,7 @@ func runHelper(r *Repo) error {
// 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.AuditLocal(); err != nil {
if err := r.AuditUncommitted(); err != nil {
return err
}
return nil
+1 -1
View File
@@ -151,7 +151,7 @@ func TestAudit(t *testing.T) {
Report: "../test_data/test_local_repo_four_alt_config_entropy.json.got",
RepoConfig: true,
},
wantPath: "../test_data/test_local_repo_four_alt_config_entropy.json.got",
wantPath: "../test_data/test_local_repo_four_alt_config_entropy.json",
},
}
+4 -2
View File
@@ -17,6 +17,7 @@ import (
"gopkg.in/src-d/go-git.v4/storage/memory"
"io"
"os"
"path"
"sync"
"time"
)
@@ -76,9 +77,9 @@ func (repo *Repo) Clone(cloneOption *git.CloneOptions) error {
return nil
}
// AuditLocal will do a `git diff` and scan changed files that are being tracked. This is useful functionality
// AuditUncommitted will do a `git diff` and scan changed files that are being tracked. This is useful functionality
// for a pre-commit hook so you can make sure your code does not have any leaks before committing.
func (repo *Repo) AuditLocal() error {
func (repo *Repo) AuditUncommitted() error {
auditTimeStart := time.Now()
r, err := repo.Head()
@@ -277,6 +278,7 @@ func (repo *Repo) Open() error {
return err
}
repo.Repository = repository
repo.Name = path.Base(dir)
}
return nil
}
+14 -10
View File
@@ -16,9 +16,7 @@ import (
// TODO documentation for
// 1. ./gitleaks --repo=https://github.com/gitleakstest/gronit -v | jq -R 'fromjson?'
// 2. Dockerfile
// 3. need to add tests for --repo-config
// 4. look over comments and code
// 5. prepare release
// 3. prepare release
func main() {
opts, err := options.ParseOptions()
@@ -55,15 +53,22 @@ func main() {
metadata := m.GetMetadata()
if len(m.GetLeaks()) != 0 {
log.Warnf("%d leaks detected. %d commits audited in %s", len(leaks),
metadata.Commits, durafmt.Parse(time.Duration(metadata.AuditTime)*time.Nanosecond))
if m.Opts.CheckUncommitted() {
log.Warnf("%d leaks detected in staged changes", len(leaks))
} else {
log.Warnf("%d leaks detected. %d commits audited in %s", len(leaks),
metadata.Commits, durafmt.Parse(time.Duration(metadata.AuditTime)*time.Nanosecond))
}
os.Exit(options.LeaksPresent)
} else {
log.Infof("No leaks detected. %d commits audited in %s",
metadata.Commits, durafmt.Parse(time.Duration(metadata.AuditTime)*time.Nanosecond))
if m.Opts.CheckUncommitted() {
log.Infof("No leaks detected in staged changes")
} else {
log.Infof("No leaks detected. %d commits audited in %s",
metadata.Commits, durafmt.Parse(time.Duration(metadata.AuditTime)*time.Nanosecond))
}
os.Exit(options.Success)
}
os.Exit(options.Success)
}
// Run begins the program and contains some basic logic on how to continue with the audit. If any external git host
@@ -71,7 +76,6 @@ func main() {
// then Audit() and Report() will be called. Otherwise, gitleaks will create a new repo and an audit will proceed.
// If no options or the uncommitted option is set then a pre-commit audit will
// take place -- this is similar to running `git diff` on all the tracked files.
// TODO handle errors from errChan
func Run(m *manager.Manager) error {
if m.Opts.Disk {
dir, err := ioutil.TempDir("", "gitleaks")
-1
View File
@@ -48,7 +48,6 @@ type Leak struct {
File string `json:"file"`
Date time.Time `json:"date"`
Tags string `json:"tags"`
Severity string `json:"severity"`
}
// AuditTime is a type used to determine total audit time
+27 -4
View File
@@ -63,8 +63,10 @@ func ParseOptions() (Options, error) {
_, err := parser.Parse()
if err != nil {
parser.WriteHelp(os.Stdout)
os.Exit(Success)
if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type != flags.ErrHelp {
parser.WriteHelp(os.Stdout)
}
os.Exit(0)
}
if opts.Version {
@@ -83,11 +85,32 @@ func ParseOptions() (Options, error) {
// If invalid sets of options are present, a descriptive error will return
// else nil is returned
func (opts Options) Guard() error {
// 1. only one target option set at a time:
// repo, owner-path, repo-path
if !oneOrNoneSet(opts.Repo, opts.OwnerPath, opts.RepoPath, opts.Host) {
return fmt.Errorf("only one target option must can be set. target options: repo, owner-path, repo-path, host")
}
if !oneOrNoneSet(opts.Organization, opts.User, opts.PullRequest) {
return fmt.Errorf("only one target option must can be set. target options: repo, owner-path, repo-path, host")
}
if !oneOrNoneSet(opts.AccessToken, opts.Password) {
log.Warn("both access-token and password are set. Only password will be attempted")
}
return nil
}
func oneOrNoneSet(optStr ...string) bool {
c := 0
for _, s := range optStr {
if s != "" {
c++
}
}
if c <= 1 {
return true
}
return false
}
// CloneOptions returns a git.cloneOptions pointer. The authentication method
// is determined by what is passed in via command-Line options. If No
// Username/PW or AccessToken is available and the repo target is not using the
+1 -2
View File
@@ -10,7 +10,6 @@
"email": "zricer@protonmail.com",
"file": "server.test.py",
"date": "2019-10-24T09:29:27-04:00",
"tags": "entropy",
"severity": ""
"tags": "entropy"
}
]
+27 -54
View File
@@ -10,8 +10,7 @@
"email": "zricer@protonmail.com",
"file": "server.test.py",
"date": "2019-10-24T09:29:27-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": " const AWSKEY = \"AKIALALEMEL33243OLIBE\"",
@@ -24,8 +23,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:12:32-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": " const AWSKEY = \"AKIALALEMEL33243OLIBE\"",
@@ -38,8 +36,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:12:08-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "Here's an AWS secret: \"AKIALALEMEL33243OLIAE\"",
@@ -52,8 +49,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:07:41-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "Here's an AWS secret: \"AKIALALEMEL33243OLIAE\"",
@@ -66,8 +62,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:01:27-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "Here's an AWS secret: AKIALALEMEL33243OLIAE",
@@ -80,8 +75,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:01:27-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "\nHere's an AWS secret: AKIALALEMEL33243OLIAE",
@@ -94,8 +88,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T12:58:39-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "const AWSKEY = \"AKIALALEMEL33243OLIAE\"",
@@ -108,8 +101,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:54:26-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "const AWSKEY = \"AKIALALEMEL33243OLIAE\"",
@@ -122,8 +114,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:54:08-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "AWS secret: \"AKIALALEMEL33243OLIAE\"",
@@ -136,8 +127,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:36:22-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "AWS secret: \"AKIALALEMEL33243OLIAE\"",
@@ -150,8 +140,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:35:03-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": " const AWSKEY = \"AKIALALEMEL33243OLIBE\"",
@@ -164,8 +153,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:12:32-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": " const AWSKEY = \"AKIALALEMEL33243OLIBE\"",
@@ -178,8 +166,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:12:08-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "Here's an AWS secret: \"AKIALALEMEL33243OLIAE\"",
@@ -192,8 +179,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:07:41-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "Here's an AWS secret: \"AKIALALEMEL33243OLIAE\"",
@@ -206,8 +192,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:01:27-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "Here's an AWS secret: AKIALALEMEL33243OLIAE",
@@ -220,8 +205,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:01:27-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "\nHere's an AWS secret: AKIALALEMEL33243OLIAE",
@@ -234,8 +218,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T12:58:39-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "const AWSKEY = \"AKIALALEMEL33243OLIAE\"",
@@ -248,8 +231,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:54:26-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "const AWSKEY = \"AKIALALEMEL33243OLIAE\"",
@@ -262,8 +244,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:54:08-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "AWS secret: \"AKIALALEMEL33243OLIAE\"",
@@ -276,8 +257,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:36:22-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "AWS secret: \"AKIALALEMEL33243OLIAE\"",
@@ -290,8 +270,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:35:03-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": " const AWSKEY = \"AKIALALEMEL33243OLIBE\"",
@@ -304,8 +283,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:12:32-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": " const AWSKEY = \"AKIALALEMEL33243OLIBE\"",
@@ -318,8 +296,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:12:08-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "Here's an AWS secret: \"AKIALALEMEL33243OLIAE\"",
@@ -332,8 +309,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:07:41-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "Here's an AWS secret: \"AKIALALEMEL33243OLIAE\"",
@@ -346,8 +322,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:01:27-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "Here's an AWS secret: AKIALALEMEL33243OLIAE",
@@ -360,8 +335,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:01:27-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "\nHere's an AWS secret: AKIALALEMEL33243OLIAE",
@@ -374,7 +348,6 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T12:58:39-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
}
]
@@ -10,8 +10,7 @@
"email": "zricer@protonmail.com",
"file": "secret.pem",
"date": "2019-10-25T13:08:39-04:00",
"tags": "entropy",
"severity": ""
"tags": "entropy"
},
{
"line": " Just moments after the Cessna's inquiry, a Twin Beech piped up on frequency, in a rather superior tone, asking for his ground speed. \"I have you at one hundred and twenty-five knots of ground spe",
@@ -24,7 +23,6 @@
"email": "zricer@protonmail.com",
"file": "secret.pem",
"date": "2019-10-25T13:07:41-04:00",
"tags": "entropy",
"severity": ""
"tags": "entropy"
}
]
+1 -2
View File
@@ -10,7 +10,6 @@
"email": "zricer@protonmail.com",
"file": "server.test.py",
"date": "2019-10-24T09:29:27-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
}
]
@@ -10,8 +10,7 @@
"email": "zricer@protonmail.com",
"file": "server.test.py",
"date": "2019-10-24T10:03:38-04:00",
"tags": "",
"severity": ""
"tags": ""
},
{
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
@@ -24,7 +23,6 @@
"email": "zricer@protonmail.com",
"file": "server.test.py",
"date": "2019-10-24T09:29:27-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
}
]
@@ -10,7 +10,6 @@
"email": "zricer@protonmail.com",
"file": "server.test.py",
"date": "2019-10-24T09:29:27-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
}
]
@@ -10,7 +10,6 @@
"email": "zricer@protonmail.com",
"file": "server.test.py",
"date": "2019-10-24T10:03:38-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
}
]
+8 -16
View File
@@ -10,8 +10,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:36:22-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "AWS secret: \"AKIALALEMEL33243OLIAE\"",
@@ -24,8 +23,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:35:03-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": " const AWSKEY = \"AKIALALEMEL33243OLIBE\"",
@@ -38,8 +36,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:12:32-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": " const AWSKEY = \"AKIALALEMEL33243OLIBE\"",
@@ -52,8 +49,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:12:08-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "Here's an AWS secret: \"AKIALALEMEL33243OLIAE\"",
@@ -66,8 +62,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:07:41-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "Here's an AWS secret: \"AKIALALEMEL33243OLIAE\"",
@@ -80,8 +75,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:01:27-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "Here's an AWS secret: AKIALALEMEL33243OLIAE",
@@ -94,8 +88,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:01:27-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "\nHere's an AWS secret: AKIALALEMEL33243OLIAE",
@@ -108,7 +101,6 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T12:58:39-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
}
]
+6 -12
View File
@@ -10,8 +10,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:12:32-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": " const AWSKEY = \"AKIALALEMEL33243OLIBE\"",
@@ -24,8 +23,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:12:08-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "Here's an AWS secret: \"AKIALALEMEL33243OLIAE\"",
@@ -38,8 +36,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:07:41-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "Here's an AWS secret: \"AKIALALEMEL33243OLIAE\"",
@@ -52,8 +49,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:01:27-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "Here's an AWS secret: AKIALALEMEL33243OLIAE",
@@ -66,8 +62,7 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:01:27-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
},
{
"line": "\nHere's an AWS secret: AKIALALEMEL33243OLIAE",
@@ -80,7 +75,6 @@
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T12:58:39-04:00",
"tags": "key, AWS",
"severity": ""
"tags": "key, AWS"
}
]
+1 -2
View File
@@ -10,7 +10,6 @@
"email": "zricer@protonmail.com",
"file": "server.test.py",
"date": "2019-10-24T09:29:27-04:00",
"tags": "entropy",
"severity": ""
"tags": "entropy"
}
]