@@ -3,6 +3,7 @@ package validate
3
3
import (
4
4
"errors"
5
5
"fmt"
6
+ "path/filepath"
6
7
7
8
"github.com/allero-io/allero/pkg/configurationManager"
8
9
localConnector "github.com/allero-io/allero/pkg/connectors/local"
@@ -59,7 +60,15 @@ allero validate ~/my-repo-dir Validate over local directory`,
59
60
Args : cobra .MaximumNArgs (1 ),
60
61
PreRun : func (cmd * cobra.Command , cmdArgs []string ) {
61
62
args := make (map [string ]any )
63
+
64
+ if len (cmdArgs ) > 0 {
65
+ absolutePath , err := filepath .Abs (cmdArgs [0 ])
66
+ if err == nil {
67
+ cmdArgs [0 ] = absolutePath
68
+ }
69
+ }
62
70
args ["Args" ] = cmdArgs
71
+
63
72
decodedToken , _ := deps .ConfigurationManager .ParseToken ()
64
73
if decodedToken != nil {
65
74
args ["User Email" ] = decodedToken .Email
@@ -158,6 +167,7 @@ func execute(deps *ValidateCommandDependencies, option *validateCommandOptions)
158
167
}
159
168
160
169
ruleResultsById := map [int ]* rulesConfig.RuleResult {}
170
+ disabledRules := map [string ]bool {}
161
171
162
172
for scmPlatform , ruleNames := range ruleNamesByScmPlatform {
163
173
for _ , ruleName := range ruleNames {
@@ -168,9 +178,8 @@ func execute(deps *ValidateCommandDependencies, option *validateCommandOptions)
168
178
169
179
isCustomRule := rule .UniqueId >= 1000
170
180
171
- if hasToken && ! selectedRuleIds [rule .UniqueId ] && ! isCustomRule {
172
- continue
173
- } else if ! hasToken && ! rule .EnabledByDefault {
181
+ if isRuleDisabled (hasToken , selectedRuleIds , rule , isCustomRule ) {
182
+ disabledRules [ruleName ] = true
174
183
continue
175
184
}
176
185
@@ -208,16 +217,13 @@ func execute(deps *ValidateCommandDependencies, option *validateCommandOptions)
208
217
209
218
summary .TotalRulesEvaluated = len (ruleResultsById )
210
219
summary .TotalFailedRules = totalRulesFailed
211
-
212
- if ! hasToken {
213
- summary .URL = deps .ConfigurationManager .TokenGenerationUrl
214
- }
220
+ summary .URL = deps .ConfigurationManager .TokenGenerationUrl
215
221
216
222
if isLocal {
217
223
ruleResultsById = reduceLocalRuleResults (ruleResultsById )
218
224
}
219
225
220
- err = resultsPrinter .PrintResults (ruleResultsById , summary , option .output , isLocal )
226
+ err = resultsPrinter .PrintResults (ruleResultsById , summary , disabledRules , option .output , isLocal )
221
227
if err != nil {
222
228
return err
223
229
}
@@ -227,6 +233,16 @@ func execute(deps *ValidateCommandDependencies, option *validateCommandOptions)
227
233
return nil
228
234
}
229
235
236
+ func isRuleDisabled (hasToken bool , selectedRuleIds map [int ]bool , rule * defaultRules.Rule , isCustomRule bool ) bool {
237
+ if hasToken && ! selectedRuleIds [rule .UniqueId ] && ! isCustomRule {
238
+ return true
239
+ } else if ! hasToken && ! rule .EnabledByDefault {
240
+ return true
241
+ }
242
+
243
+ return false
244
+ }
245
+
230
246
func reduceLocalRuleResults (ruleResultsById map [int ]* rulesConfig.RuleResult ) map [int ]* rulesConfig.RuleResult {
231
247
reducedRuleResultsById := map [int ]* rulesConfig.RuleResult {}
232
248
for uniqueId , ruleResult := range ruleResultsById {
0 commit comments