-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from kubescape/feature/generic_path_analyzer
Added dynamic open path detector
- Loading branch information
Showing
18 changed files
with
331 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package dynamicpathdetector | ||
|
||
import ( | ||
"fmt" | ||
"slices" | ||
|
||
mapset "github.com/deckarep/golang-set/v2" | ||
types "github.com/kubescape/storage/pkg/apis/softwarecomposition" | ||
) | ||
|
||
func AnalyzeOpens(opens []types.OpenCalls, analyzer *PathAnalyzer) ([]types.OpenCalls, error) { | ||
var dynamicOpens []types.OpenCalls | ||
for _, open := range opens { | ||
_, _ = AnalyzeOpen(open.Path, analyzer) | ||
} | ||
|
||
for i := range opens { | ||
result, err := AnalyzeOpen(opens[i].Path, analyzer) | ||
if err != nil { | ||
continue | ||
} | ||
|
||
if result != opens[i].Path { | ||
if existing, err := getIfExists(result, dynamicOpens); err == nil { | ||
existing.Flags = mapset.Sorted(mapset.NewThreadUnsafeSet(slices.Concat(existing.Flags, opens[i].Flags)...)) | ||
} else { | ||
dynamicOpen := types.OpenCalls{Path: result, Flags: opens[i].Flags} | ||
dynamicOpens = append(dynamicOpens, dynamicOpen) | ||
} | ||
} else { | ||
dynamicOpens = append(dynamicOpens, opens[i]) | ||
} | ||
} | ||
|
||
return dynamicOpens, nil | ||
} | ||
|
||
func AnalyzeOpen(path string, analyzer *PathAnalyzer) (string, error) { | ||
return analyzer.AnalyzePath(path, "opens") | ||
} | ||
|
||
func getIfExists(path string, dynamicOpens []types.OpenCalls) (*types.OpenCalls, error) { | ||
for i := range dynamicOpens { | ||
if dynamicOpens[i].Path == path { | ||
return &dynamicOpens[i], nil | ||
} | ||
} | ||
return nil, fmt.Errorf("not found") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.