repoDescriptor->repoInfo

This commit is contained in:
zach rice committed 2019-03-28 08:06:38 -05:00
1 parent e79ffc6ae8
commit c2143c5843
9 files changed
+23 -28

No files matched your search

+1 -1
View File
@@ -3,5 +3,5 @@ package main
import "github.com/zricethezav/gitleaks/src" import "github.com/zricethezav/gitleaks/src"
func main() { func main() {
gitleaks.Run() gitleaks.Run(gitleaks.ParseOpts())
} }
+1 -1
View File
@@ -177,7 +177,7 @@ func (config *Config) updateEntropyRanges(entropyLimitStr []string) error {
// externalConfig will attempt to load a pinned ".gitleaks.toml" configuration file // externalConfig will attempt to load a pinned ".gitleaks.toml" configuration file
// from a remote or local repo. Use the --repo-config option to trigger this. // from a remote or local repo. Use the --repo-config option to trigger this.
func (config *Config) updateFromRepo(repo *RepoDescriptor) error { func (config *Config) updateFromRepo(repo *RepoInfo) error {
var tomlConfig TomlConfig var tomlConfig TomlConfig
wt, err := repo.repository.Worktree() wt, err := repo.repository.Worktree()
if err != nil { if err != nil {
-1
View File
@@ -1 +0,0 @@
package gitleaks
+3 -6
View File
@@ -57,15 +57,12 @@ func init() {
} }
// Run is the entry point for gitleaks // Run is the entry point for gitleaks
func Run() { func Run(optsL *Options) {
var ( var (
leaks []Leak leaks []Leak
err error err error
) )
opts, err = setupOpts() opts = optsL
if err != nil {
log.Fatal(err)
}
config, err = newConfig() config, err = newConfig()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -84,7 +81,7 @@ func Run() {
// start audits // start audits
if opts.Repo != "" || opts.RepoPath != "" { if opts.Repo != "" || opts.RepoPath != "" {
repoD, err := newRepoD() repoD, err := newRepoInfo()
if err != nil { if err != nil {
goto postAudit goto postAudit
} }
+2 -2
View File
@@ -188,7 +188,7 @@ func auditGithubRepos() ([]Leak, error) {
// cloneGithubRepo clones a repo from the url parsed from a github repo. The repo // cloneGithubRepo clones a repo from the url parsed from a github repo. The repo
// will be cloned to disk if --disk is set. // will be cloned to disk if --disk is set.
func cloneGithubRepo(githubRepo *github.Repository) (*RepoDescriptor, error) { func cloneGithubRepo(githubRepo *github.Repository) (*RepoInfo, error) {
var ( var (
repo *git.Repository repo *git.Repository
err error err error
@@ -249,7 +249,7 @@ func cloneGithubRepo(githubRepo *github.Repository) (*RepoDescriptor, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &RepoDescriptor{ return &RepoInfo{
repository: repo, repository: repo,
name: *githubRepo.Name, name: *githubRepo.Name,
}, nil }, nil
+2 -2
View File
@@ -121,7 +121,7 @@ func createGitlabTempDir() (string, error) {
return ownerDir, nil return ownerDir, nil
} }
func cloneGitlabRepo(tempDir string, p *gitlab.Project) (*RepoDescriptor, error) { func cloneGitlabRepo(tempDir string, p *gitlab.Project) (*RepoInfo, error) {
var ( var (
repo *git.Repository repo *git.Repository
err error err error
@@ -157,7 +157,7 @@ func cloneGitlabRepo(tempDir string, p *gitlab.Project) (*RepoDescriptor, error)
return nil, err return nil, err
} }
return &RepoDescriptor{ return &RepoInfo{
repository: repo, repository: repo,
name: p.Name, name: p.Name,
}, nil }, nil
+3 -4
View File
@@ -56,7 +56,7 @@ type Options struct {
SampleConfig bool `long:"sample-config" description:"prints a sample config file"` SampleConfig bool `long:"sample-config" description:"prints a sample config file"`
} }
func setupOpts() (*Options, error) { func ParseOpts() (*Options) {
var opts Options var opts Options
parser := flags.NewParser(&opts, flags.Default) parser := flags.NewParser(&opts, flags.Default)
_, err := parser.Parse() _, err := parser.Parse()
@@ -86,10 +86,9 @@ func setupOpts() (*Options, error) {
err = opts.guard() err = opts.guard()
if err != nil { if err != nil {
return nil, err log.Fatal(err)
} }
return &opts, err return &opts
} }
// optsGuard prevents invalid options // optsGuard prevents invalid options
+8 -8
View File
@@ -17,8 +17,8 @@ import (
"gopkg.in/src-d/go-git.v4/storage/memory" "gopkg.in/src-d/go-git.v4/storage/memory"
) )
// RepoDescriptor contains a src-d git repository and other data about the repo // RepoInfo contains a src-d git repository and other data about the repo
type RepoDescriptor struct { type RepoInfo struct {
path string path string
url string url string
name string name string
@@ -26,20 +26,20 @@ type RepoDescriptor struct {
err error err error
} }
func newRepoD() (*RepoDescriptor, error) { func newRepoInfo() (*RepoInfo, error) {
for _, re := range config.WhiteList.repos { for _, re := range config.WhiteList.repos {
if re.FindString(opts.Repo) != "" { if re.FindString(opts.Repo) != "" {
return nil, fmt.Errorf("skipping %s, whitelisted", opts.Repo) return nil, fmt.Errorf("skipping %s, whitelisted", opts.Repo)
} }
} }
return &RepoDescriptor{ return &RepoInfo{
path: opts.RepoPath, path: opts.RepoPath,
url: opts.Repo, url: opts.Repo,
name: filepath.Base(opts.Repo), name: filepath.Base(opts.Repo),
}, nil }, nil
} }
func (repoD *RepoDescriptor) clone() error { func (repoD *RepoInfo) clone() error {
var ( var (
err error err error
repo *git.Repository repo *git.Repository
@@ -57,7 +57,7 @@ func (repoD *RepoDescriptor) clone() error {
Auth: config.sshAuth, Auth: config.sshAuth,
}) })
} else { } else {
// non-private // public
repo, err = git.PlainClone(cloneTarget, false, &git.CloneOptions{ repo, err = git.PlainClone(cloneTarget, false, &git.CloneOptions{
URL: opts.Repo, URL: opts.Repo,
Progress: os.Stdout, Progress: os.Stdout,
@@ -87,7 +87,7 @@ func (repoD *RepoDescriptor) clone() error {
return err return err
} }
func (repoD *RepoDescriptor) audit() ([]Leak, error) { func (repoD *RepoInfo) audit() ([]Leak, error) {
var ( var (
err error err error
leaks []Leak leaks []Leak
@@ -128,7 +128,7 @@ func (repoD *RepoDescriptor) audit() ([]Leak, error) {
// auditGitReference beings the audit for a git reference. This function will // auditGitReference beings the audit for a git reference. This function will
// traverse the git reference and audit each line of each diff. // traverse the git reference and audit each line of each diff.
func (repoD *RepoDescriptor) auditRef(ref *plumbing.Reference) []Leak { func (repoD *RepoInfo) auditRef(ref *plumbing.Reference) []Leak {
var ( var (
err error err error
repoName string repoName string
+3 -3
View File
@@ -154,10 +154,10 @@ func addLeak(leaks []Leak, line string, offender string, leakType string, diff g
// discoverRepos walks all the children of `path`. If a child directory // discoverRepos walks all the children of `path`. If a child directory
// contain a .git subdirectory then that repo will be added to the list of repos returned // contain a .git subdirectory then that repo will be added to the list of repos returned
func discoverRepos(ownerPath string) ([]*RepoDescriptor, error) { func discoverRepos(ownerPath string) ([]*RepoInfo, error) {
var ( var (
err error err error
repoDs []*RepoDescriptor repoDs []*RepoInfo
) )
files, err := ioutil.ReadDir(ownerPath) files, err := ioutil.ReadDir(ownerPath)
if err != nil { if err != nil {
@@ -166,7 +166,7 @@ func discoverRepos(ownerPath string) ([]*RepoDescriptor, error) {
for _, f := range files { for _, f := range files {
repoPath := path.Join(ownerPath, f.Name()) repoPath := path.Join(ownerPath, f.Name())
if f.IsDir() && containsGit(repoPath) { if f.IsDir() && containsGit(repoPath) {
repoDs = append(repoDs, &RepoDescriptor{ repoDs = append(repoDs, &RepoInfo{
name: f.Name(), name: f.Name(),
path: repoPath, path: repoPath,
}) })