Skip to content

Commit

Permalink
🐛 Handle missing containerless-deps (#349)
Browse files Browse the repository at this point in the history
* Handle missing containerless-deps

Missing container-kantra-deps setup caused kantra analyze-bin command
segfault. Adding check and error message to fail nicely.

Related to: #338

Signed-off-by: Marek Aufart <[email protected]>

* Update .kantra subdirs validation

Signed-off-by: Marek Aufart <[email protected]>

* Update RulesetsLocation path from const

Signed-off-by: Marek Aufart <[email protected]>

---------

Signed-off-by: Marek Aufart <[email protected]>
  • Loading branch information
aufi authored Oct 2, 2024
1 parent 6d86360 commit 9f8a286
Showing 1 changed file with 14 additions and 0 deletions.
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")
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

0 comments on commit 9f8a286

Please sign in to comment.