-
Notifications
You must be signed in to change notification settings - Fork 88
Enable conan support #781
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
Enable conan support #781
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
273de55
conan package handler
orto17 43652da
IsFileExists fix
orto17 915615d
conan package handler
orto17 54de62d
IsFileExists fix
orto17 ec66723
conan tests
orto17 a000527
fixed installation command
orto17 03bca77
test fix
orto17 a190aed
Install Conan in test yaml
orto17 3e62106
Install Conan in test yaml
orto17 1e35c80
Install Conan in test yaml
orto17 00354d5
one more commit
orto17 436c582
conan profile detect
orto17 02cd719
removed installation part
orto17 f770023
GetAllDescriptorFilesFullPaths
orto17 151843a
fixed tests data structure
orto17 464a979
error messages change
orto17 4dc212f
static analysis fix
orto17 19d3822
tests update
orto17 91c07fd
removed logNoInstallationMessage
orto17 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
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 |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package packagehandlers | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "github.com/jfrog/frogbot/v2/utils" | ||
| "github.com/jfrog/jfrog-client-go/utils/log" | ||
| "os" | ||
| "strings" | ||
| ) | ||
|
|
||
| const ( | ||
| conanFileTxt = "conanfile.txt" | ||
| conanFilePy = "conanfile.py" | ||
| ) | ||
|
|
||
| type ConanPackageHandler struct { | ||
| CommonPackageHandler | ||
| } | ||
|
|
||
| func (conan *ConanPackageHandler) UpdateDependency(vulnDetails *utils.VulnerabilityDetails) error { | ||
| if vulnDetails.IsDirectDependency { | ||
| return conan.updateDirectDependency(vulnDetails) | ||
| } else { | ||
| return &utils.ErrUnsupportedFix{ | ||
| PackageName: vulnDetails.ImpactedDependencyName, | ||
| FixedVersion: vulnDetails.SuggestedFixedVersion, | ||
| ErrorType: utils.IndirectDependencyFixNotSupported, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func (conan *ConanPackageHandler) updateDirectDependency(vulnDetails *utils.VulnerabilityDetails) (err error) { | ||
| conanDescriptors, err := conan.CommonPackageHandler.GetAllDescriptorFilesFullPaths([]string{conanFileTxt, conanFilePy}) | ||
| if err != nil { | ||
| err = fmt.Errorf("failed while searching for Conan descriptor files in project: %s", err.Error()) | ||
| return | ||
| } | ||
| isAnyDescriptorFileChanged := false | ||
| for _, descriptor := range conanDescriptors { | ||
| var isFileChanged bool | ||
| isFileChanged, err = conan.updateConanFile(descriptor, vulnDetails) | ||
| if err != nil { | ||
| return | ||
| } | ||
| isAnyDescriptorFileChanged = isAnyDescriptorFileChanged || isFileChanged | ||
| } | ||
| if !isAnyDescriptorFileChanged { | ||
| err = fmt.Errorf("impacted package '%s' was not found or could not be fixed in all descriptor files", vulnDetails.ImpactedDependencyName) | ||
| } else { | ||
| log.Info("Requirements file was updated with a suggested fix version, but no installation was performed. " + | ||
| "In order to update the dependencies, please run 'conan install' command") | ||
| } | ||
| return | ||
| } | ||
|
|
||
| func (conan *ConanPackageHandler) updateConanFile(conanFilePath string, vulnDetails *utils.VulnerabilityDetails) (isFileChanged bool, err error) { | ||
| data, err := os.ReadFile(conanFilePath) | ||
| if err != nil { | ||
| return false, fmt.Errorf("an error occurred while attempting to read the requirements file '%s': %s\n", conanFilePath, err.Error()) | ||
| } | ||
| currentFile := string(data) | ||
| fixedPackage := vulnDetails.ImpactedDependencyName + "/" + vulnDetails.SuggestedFixedVersion | ||
| impactedDependency := vulnDetails.ImpactedDependencyName + "/" + vulnDetails.ImpactedDependencyVersion | ||
| fixedFile := strings.Replace(currentFile, impactedDependency, strings.ToLower(fixedPackage), 1) | ||
|
|
||
| if fixedFile == currentFile { | ||
| log.Debug(fmt.Sprintf("impacted dependency '%s' not found in descriptor '%s', moving to the next descriptor if exists...", impactedDependency, conanFilePath)) | ||
| return false, nil | ||
| } | ||
| if err = os.WriteFile(conanFilePath, []byte(fixedFile), 0600); err != nil { | ||
| err = fmt.Errorf("an error occured while writing the fixed version of %s to the requirements file '%s': %s", vulnDetails.ImpactedDependencyName, conanFilePath, err.Error()) | ||
| } | ||
| isFileChanged = true | ||
| return | ||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| from conan import ConanFile | ||
|
|
||
| class MyPackage(ConanFile): | ||
| name = "my_package" | ||
| version = "1.0.0" | ||
|
|
||
| requires = [ | ||
| "zlib/1.3.1", | ||
| "openssl/3.0.9", | ||
| "meson/1.4.1" | ||
| ] | ||
|
|
||
| def build_requirements(self): | ||
| self.build_requires("meson/1.4.1") | ||
|
|
||
| def build(self): | ||
| pass | ||
|
|
||
| def package(self): | ||
| pass | ||
|
|
||
| def package_info(self): | ||
| pass |
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 |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| [requires] | ||
| zlib/1.3.1 | ||
| openssl/3.0.9 | ||
| meson/1.4.1 |
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 |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| [settings] | ||
| arch=x86_64 | ||
| build_type=Release | ||
| compiler=gcc | ||
| compiler.cppstd=gnu17 | ||
| compiler.libcxx=libstdc++11 | ||
| compiler.version=11 | ||
| os=Linux |
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.