Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Handle missing containerless-deps #349

Merged
merged 3 commits into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cmd/analyze-bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,16 @@ func NewAnalyzeBinCmd(log logr.Logger) *cobra.Command {
}

func (b *analyzeBinCommand) Validate(ctx context.Context) error {
// Validate .kantra in home directory and its content (containerless)
requiredDirs := []string{b.homeKantraDir, filepath.Join(b.homeKantraDir, RulesetsLocation), filepath.Join(b.homeKantraDir, JavaBundlesLocation), filepath.Join(b.homeKantraDir, JDTLSBinLocation)}
for _, path := range requiredDirs {
if _, err := os.Stat(path); os.IsNotExist(err) {
b.log.Error(err, "cannot open required path, ensure that container-less dependencies are installed")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example error messages for missing rulesets:

ERRO[0000] cannot open required path, ensure that container-less dependencies are installed  error="stat /home/.../.kantra/rulesets: no such file or directory"

return err
}
}

// Print-only methods
if b.listSources || b.listTargets {
return nil
}
Expand Down Expand Up @@ -430,6 +440,10 @@ func (b *analyzeBinCommand) fetchLabels(ctx context.Context, listSources, listTa
func (b *analyzeBinCommand) walkRuleFilesForLabels(label string) ([]string, error) {
labelsSlice := []string{}
path := filepath.Join(b.homeKantraDir, RulesetsLocation)
if _, err := os.Stat(path); os.IsNotExist(err) {
b.log.Error(err, "cannot open provided path")
return nil, err
}
err := filepath.WalkDir(path, walkRuleSets(path, label, &labelsSlice))
if err != nil {
return nil, err
Expand Down
Loading