Skip to content

Commit e9739d6

Browse files
committed
[PLUTO-1412] fix semgrep loading
1 parent 85474e2 commit e9739d6

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

tools/semgrepConfigCreator.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,15 @@ func FilterRulesFromFile(rulesFilePath string, config []domain.PatternConfigurat
6565

6666
// GetSemgrepConfig gets the Semgrep configuration based on the pattern configuration
6767
func GetSemgrepConfig(config []domain.PatternConfiguration) ([]byte, error) {
68-
// Get the default rules file location
69-
rulesFile := filepath.Join("plugins", "tools", "semgrep", "rules.yaml")
68+
// Get the executable's directory
69+
execPath, err := os.Executable()
70+
if err != nil {
71+
return nil, fmt.Errorf("failed to get executable path: %w", err)
72+
}
73+
execDir := filepath.Dir(execPath)
74+
75+
// Get the default rules file location relative to the executable
76+
rulesFile := filepath.Join(execDir, "plugins", "tools", "semgrep", "rules.yaml")
7077

7178
// Check if it exists and config is not empty
7279
if _, err := os.Stat(rulesFile); err == nil && len(config) > 0 {
@@ -80,8 +87,15 @@ func GetSemgrepConfig(config []domain.PatternConfiguration) ([]byte, error) {
8087

8188
// GetDefaultSemgrepConfig gets the default Semgrep configuration
8289
func GetDefaultSemgrepConfig() ([]byte, error) {
83-
// Get the default rules file location
84-
rulesFile := filepath.Join("plugins", "tools", "semgrep", "rules.yaml")
90+
// Get the executable's directory
91+
execPath, err := os.Executable()
92+
if err != nil {
93+
return nil, fmt.Errorf("failed to get executable path: %w", err)
94+
}
95+
execDir := filepath.Dir(execPath)
96+
97+
// Get the default rules file location relative to the executable
98+
rulesFile := filepath.Join(execDir, "plugins", "tools", "semgrep", "rules.yaml")
8599

86100
// If the file exists, return its contents
87101
if _, err := os.Stat(rulesFile); err == nil {

0 commit comments

Comments
 (0)