Skip to content

Commit

Permalink
feat: add ignore-git flag to force the scan
Browse files Browse the repository at this point in the history
  • Loading branch information
cfabianski committed Sep 21, 2023
1 parent 6976b1f commit 1944db4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
24 changes: 13 additions & 11 deletions internal/commands/process/filelist/filelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,23 @@ import (
func Discover(repository *gitrepository.Repository, targetPath string, goclocResult *gocloc.Result, config settings.Config) (*flfiles.List, error) {
ignore := ignore.New(targetPath, config)

fileList, err := repository.ListFiles(ignore, goclocResult)
if err != nil {
log.Error().Msg("Git discovery failed")
return nil, err
}
if !config.IgnoreGit {
fileList, err := repository.ListFiles(ignore, goclocResult)
if err != nil {
log.Error().Msg("Git discovery failed")
return nil, err
}

if fileList != nil {
log.Debug().Msg("Files found from Git")
return fileList, nil
}
if fileList != nil {
log.Debug().Msg("Files found from Git")
return fileList, nil
}

log.Debug().Msg("No files found from Git")
log.Debug().Msg("No files found from Git")
}

var files []flfiles.File
err = filepath.WalkDir(targetPath, func(filePath string, d fs.DirEntry, err error) error {
err := filepath.WalkDir(targetPath, func(filePath string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion internal/commands/process/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ type Config struct {
BearerRulesVersion string `mapstructure:"bearer_rules_version" json:"bearer_rules_version" yaml:"bearer_rules_version"`
NoColor bool `mapstructure:"no_color" json:"no_color" yaml:"no_color"`
Debug bool `mapstructure:"debug" json:"debug" yaml:"debug"`
LogLevel string `mapstructure:"string" json:"string" yaml:"string"`
LogLevel string `mapstructure:"log_level" json:"log_level" yaml:"log_level"`
DebugProfile bool `mapstructure:"debug_profile" json:"debug_profile" yaml:"debug_profile"`
IgnoreGit bool `mapstructure:"ignore_git" json:"ignore_git" yaml:"ignore_git"`
}

type Modules []*PolicyModule
Expand Down Expand Up @@ -354,6 +355,7 @@ func FromOptions(opts flag.Options, versionMeta *version_check.VersionMeta) (Con
Debug: opts.GeneralOptions.Debug,
LogLevel: opts.GeneralOptions.LogLevel,
IgnoreFile: opts.GeneralOptions.IgnoreFile,
IgnoreGit: opts.GeneralOptions.IgnoreGit,
Policies: policies,
Rules: result.Rules,
BuiltInRules: result.BuiltInRules,
Expand Down
13 changes: 13 additions & 0 deletions internal/flag/general_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ var (
Hide: true,
DisableInConfig: true,
}
IgnoreGitFlag = Flag{
Name: "ignore-git",
ConfigName: "ignore-git",
Value: false,
Usage: "Ignore Git listing",
Hide: true,
DisableInConfig: true,
}
)

type GeneralFlagGroup struct {
Expand All @@ -91,6 +99,7 @@ type GeneralFlagGroup struct {
DebugFlag *Flag
LogLevelFlag *Flag
DebugProfile *Flag
IgnoreGit *Flag
}

// GlobalOptions defines flags and other configuration parameters for all the subcommands
Expand All @@ -103,6 +112,7 @@ type GeneralOptions struct {
Debug bool `mapstructure:"debug" json:"debug" yaml:"debug"`
LogLevel string `mapstructure:"log-level" json:"log-level" yaml:"log-level"`
DebugProfile bool
IgnoreGit bool `mapstructure:"ignore-git" json:"ignore-git" yaml:"ignore-git"`
}

func NewGeneralFlagGroup() *GeneralFlagGroup {
Expand All @@ -116,6 +126,7 @@ func NewGeneralFlagGroup() *GeneralFlagGroup {
DebugFlag: &DebugFlag,
LogLevelFlag: &LogLevelFlag,
DebugProfile: &DebugProfileFlag,
IgnoreGit: &IgnoreGitFlag,
}
}

Expand All @@ -134,6 +145,7 @@ func (f *GeneralFlagGroup) Flags() []*Flag {
f.DebugFlag,
f.LogLevelFlag,
f.DebugProfile,
f.IgnoreGit,
}
}

Expand Down Expand Up @@ -169,6 +181,7 @@ func (f *GeneralFlagGroup) ToOptions() GeneralOptions {
IgnoreFile: getString(f.IgnoreFile),
Debug: debug,
LogLevel: logLevel,
IgnoreGit: getBool(f.IgnoreGit),
DebugProfile: getBool(f.DebugProfile),
}
}

0 comments on commit 1944db4

Please sign in to comment.