-
Notifications
You must be signed in to change notification settings - Fork 10
feat: Add trivy along with Add support for download-based tools PLUTO-1360 PLUTO-1361 #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7209462
feat: Add trivy along with Add support for download-based tools and e…
andrzej-janczak 0301fa9
refactor: Simplify tool installation logic by removing temporary extr…
andrzej-janczak 9604a07
chore: Remove unused formatters and output options from trivy plugin …
andrzej-janczak c0193ae
feature: Add trivy as a runner
machadoit a6279a9
feature: Add support for trivy configuration
machadoit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -2,3 +2,4 @@ runtimes: | |
| - [email protected] | ||
| tools: | ||
| - [email protected] | ||
| - [email protected] | ||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -72,20 +72,25 @@ | |
|
|
||
| func configFileTemplate(tools []tools.Tool) string { | ||
|
|
||
| // Default version | ||
| // Default versions | ||
| eslintVersion := "9.3.0" | ||
| trivyVersion := "0.59.1" // Latest stable version | ||
|
|
||
| for _, tool := range tools { | ||
| if tool.Uuid == "f8b29663-2cb2-498d-b923-a10c6a8c05cd" { | ||
| eslintVersion = tool.Version | ||
| } | ||
| if tool.Uuid == "2fd7fbe0-33f9-4ab3-ab73-e9b62404e2cb" { | ||
| trivyVersion = tool.Version | ||
| } | ||
| } | ||
|
|
||
| return fmt.Sprintf(`runtimes: | ||
| - [email protected] | ||
| tools: | ||
| - eslint@%s | ||
| `, eslintVersion) | ||
| - trivy@%s | ||
| `, eslintVersion, trivyVersion) | ||
| } | ||
|
|
||
| func buildRepositoryConfigurationFiles(token string) error { | ||
|
|
@@ -150,7 +155,24 @@ | |
| _, err = eslintConfigFile.WriteString(eslintConfigurationString) | ||
| if err != nil { | ||
| log.Fatal(err) | ||
| } | ||
|
|
||
| // Create Trivy configuration after processing ESLint | ||
| trivyApiConfiguration := extractTrivyConfiguration(apiToolConfigurations) | ||
| if trivyApiConfiguration != nil { | ||
| // Create trivy.yaml file based on API configuration | ||
| err = createTrivyConfigFile(*trivyApiConfiguration) | ||
| if err != nil { | ||
| log.Fatal(err) | ||
| } | ||
| fmt.Println("Trivy configuration created based on Codacy settings") | ||
| } else { | ||
| // Create default trivy.yaml if no configuration from API | ||
| err = createDefaultTrivyConfigFile() | ||
| if err != nil { | ||
| log.Fatal(err) | ||
| } | ||
| fmt.Println("Default Trivy configuration created") | ||
| } | ||
|
|
||
| return nil | ||
|
|
@@ -197,6 +219,20 @@ | |
| return nil | ||
| } | ||
|
|
||
| // extractTrivyConfiguration extracts Trivy configuration from the Codacy API response | ||
| func extractTrivyConfiguration(toolConfigurations []CodacyToolConfiguration) *CodacyToolConfiguration { | ||
| // Trivy internal codacy uuid | ||
| const TrivyUUID = "2fd7fbe0-33f9-4ab3-ab73-e9b62404e2cb" | ||
|
|
||
| for _, toolConfiguration := range toolConfigurations { | ||
| if toolConfiguration.Uuid == TrivyUUID { | ||
| return &toolConfiguration | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| type CodacyToolConfiguration struct { | ||
| Uuid string `json:"uuid"` | ||
| IsEnabled bool `json:"isEnabled"` | ||
|
|
@@ -212,3 +248,65 @@ | |
| name string `json:"name"` | ||
| value string `json:"value"` | ||
| } | ||
|
|
||
| // createTrivyConfigFile creates a trivy.yaml configuration file based on the API configuration | ||
| func createTrivyConfigFile(config CodacyToolConfiguration) error { | ||
| // Convert CodacyToolConfiguration to tools.ToolConfiguration | ||
| trivyDomainConfiguration := convertAPIToolConfigurationForTrivy(config) | ||
|
|
||
| // Use the shared CreateTrivyConfig function to generate the config content | ||
| trivyConfigurationString := tools.CreateTrivyConfig(trivyDomainConfiguration) | ||
|
|
||
| // Write to file | ||
| return os.WriteFile("trivy.yaml", []byte(trivyConfigurationString), 0644) | ||
| } | ||
|
|
||
| // convertAPIToolConfigurationForTrivy converts API tool configuration to domain model for Trivy | ||
| func convertAPIToolConfigurationForTrivy(config CodacyToolConfiguration) tools.ToolConfiguration { | ||
| var patterns []tools.PatternConfiguration | ||
|
|
||
| // Only process if tool is enabled | ||
| if config.IsEnabled { | ||
| for _, pattern := range config.Patterns { | ||
| var parameters []tools.PatternParameterConfiguration | ||
|
|
||
| // By default patterns are enabled | ||
| patternEnabled := true | ||
|
|
||
| // Check if there's an explicit enabled parameter | ||
| for _, param := range pattern.Parameters { | ||
| if param.name == "enabled" && param.value == "false" { | ||
| patternEnabled = false | ||
| } | ||
| } | ||
|
|
||
| // Add enabled parameter | ||
| parameters = append(parameters, tools.PatternParameterConfiguration{ | ||
| Name: "enabled", | ||
| Value: fmt.Sprintf("%t", patternEnabled), | ||
| }) | ||
|
|
||
| patterns = append( | ||
| patterns, | ||
| tools.PatternConfiguration{ | ||
| PatternId: pattern.InternalId, | ||
| ParamenterConfigurations: parameters, | ||
| }, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| return tools.ToolConfiguration{ | ||
| PatternsConfiguration: patterns, | ||
| } | ||
| } | ||
|
|
||
| // createDefaultTrivyConfigFile creates a default trivy.yaml configuration file | ||
| func createDefaultTrivyConfigFile() error { | ||
| // Use empty tool configuration to get default settings | ||
| emptyConfig := tools.ToolConfiguration{} | ||
| content := tools.CreateTrivyConfig(emptyConfig) | ||
|
|
||
| // Write to file | ||
| return os.WriteFile("trivy.yaml", []byte(content), 0644) | ||
| } | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return ❤️ 🥲