Skip to content

Commit

Permalink
Add --enable-default-rulesets flag (#133)
Browse files Browse the repository at this point in the history
--enable-default-rulesets flag

Signed-off-by: Emily McMullan <[email protected]>
  • Loading branch information
eemcmullan authored Jan 2, 2024
1 parent 3862095 commit 492e555
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ RUN CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -a -o windows-kantra main.g

FROM quay.io/konveyor/analyzer-lsp:latest

RUN mkdir /opt/rulesets /opt/rulesets/input /opt/rulesets/convert /opt/openrewrite /opt/input /opt/output /opt/xmlrules /opt/shimoutput
RUN mkdir /opt/rulesets /opt/rulesets/input /opt/rulesets/convert /opt/openrewrite /opt/input /opt/input/rules /opt/input/rules/custom /opt/output /opt/xmlrules /opt/shimoutput

COPY --from=builder /workspace/kantra /usr/local/bin/kantra
COPY --from=builder /workspace/darwin-kantra /usr/local/bin/darwin-kantra
Expand Down
34 changes: 29 additions & 5 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type analyzeCommand struct {
mode string
rules []string
jaegerEndpoint string
enableDefaultRulesets bool

// tempDirs list of temporary dirs created, used for cleanup
tempDirs []string
Expand Down Expand Up @@ -158,6 +159,7 @@ func NewAnalyzeCmd(log logr.Logger) *cobra.Command {
analyzeCommand.Flags().BoolVar(&analyzeCmd.jsonOutput, "json-output", false, "create analysis and dependency output as json")
analyzeCommand.Flags().BoolVar(&analyzeCmd.overwrite, "overwrite", false, "overwrite output directory")
analyzeCommand.Flags().StringVar(&analyzeCmd.jaegerEndpoint, "jaeger-endpoint", "", "jaeger endpoint to collect traces")
analyzeCommand.Flags().BoolVar(&analyzeCmd.enableDefaultRulesets, "enable-default-rulesets", true, "run default rulesets with analysis")

return analyzeCommand
}
Expand Down Expand Up @@ -229,6 +231,9 @@ func (a *analyzeCommand) Validate() error {
if absPath, err := filepath.Abs(a.mavenSettingsFile); a.mavenSettingsFile != "" && err == nil {
a.mavenSettingsFile = absPath
}
if !a.enableDefaultRulesets && len(a.rules) == 0 {
return fmt.Errorf("must specify rules if default rulesets are not enabled")
}
return nil
}

Expand Down Expand Up @@ -526,7 +531,12 @@ func (a *analyzeCommand) getRulesVolumes() (map[string]string, error) {
}

} else {
rulesVolumes[r] = path.Join(RulesMountPath, filepath.Base(r))
if !a.enableDefaultRulesets {
rulesVolumes[r] = path.Join(CustomRulePath, filepath.Base(r))
} else {
rulesVolumes[r] = path.Join(RulesMountPath, filepath.Base(r))
}

}
}
if rulesetNeeded {
Expand All @@ -536,7 +546,11 @@ func (a *analyzeCommand) getRulesVolumes() (map[string]string, error) {
a.log.V(1).Error(err, "failed to create temp ruleset", "path", tempRulesetPath)
return nil, err
}
rulesVolumes[tempDir] = path.Join(RulesMountPath, filepath.Base(tempDir))
if !a.enableDefaultRulesets {
rulesVolumes[tempDir] = path.Join(CustomRulePath, filepath.Base(tempDir))
} else {
rulesVolumes[tempDir] = path.Join(RulesMountPath, filepath.Base(tempDir))
}
}
return rulesVolumes, nil
}
Expand Down Expand Up @@ -582,9 +596,13 @@ func (a *analyzeCommand) RunAnalysis(ctx context.Context, xmlOutputDir string) e
// output directory
a.output: OutputPath,
}

var convertPath string
if xmlOutputDir != "" {
convertPath := path.Join(RulesetPath, "convert")
if !a.enableDefaultRulesets {
convertPath = path.Join(CustomRulePath, "convert")
} else {
convertPath = path.Join(RulesetPath, "convert")
}
volumes[xmlOutputDir] = convertPath
// for cleanup purposes
a.tempDirs = append(a.tempDirs, xmlOutputDir)
Expand All @@ -608,10 +626,16 @@ func (a *analyzeCommand) RunAnalysis(ctx context.Context, xmlOutputDir string) e

args := []string{
fmt.Sprintf("--provider-settings=%s", ProviderSettingsMountPath),
fmt.Sprintf("--rules=%s/", RulesetPath),
fmt.Sprintf("--output-file=%s", AnalysisOutputMountPath),
fmt.Sprintf("--context-lines=%d", 100),
}
if a.enableDefaultRulesets {
args = append(args,
fmt.Sprintf("--rules=%s/", RulesetPath))
} else {
args = append(args,
fmt.Sprintf("--rules=%s/", CustomRulePath))
}
if a.jaegerEndpoint != "" {
args = append(args, "--enable-jaeger")
args = append(args, "--jaeger-endpoint")
Expand Down
1 change: 1 addition & 0 deletions cmd/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
OutputPath = "/opt/output"
XMLRulePath = "/opt/xmlrules"
ShimOutputPath = "/opt/shimoutput"
CustomRulePath = "/opt/input/rules"
)

type Config struct {
Expand Down

0 comments on commit 492e555

Please sign in to comment.