-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor scanner to support provider/url
- Loading branch information
Showing
76 changed files
with
1,002 additions
and
770 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 was deleted.
Oops, something went wrong.
This file contains 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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,30 @@ | ||
package cratesio | ||
|
||
import ( | ||
es "cvepack/core/ecosystem" | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
func NewProjectFromProvider(provider es.Provider) (es.Project, error) { | ||
cargoFilePath := provider.GetFirstExistingPath(CargoFile) | ||
|
||
// check for Cargo.toml first | ||
if cargoFilePath != "" { | ||
cargoLockFilePath := provider.GetFirstExistingPath(CargoLockFile) | ||
|
||
// then check for Cargo.lock | ||
if cargoLockFilePath != "" { | ||
content, err := es.ProviderPathContent(provider, cargoLockFilePath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return es.NewProject(provider.Source().Value, EcosystemName, parseCargoLockContent(content)), nil | ||
} | ||
|
||
// otherwise, fall back to Cargo.toml | ||
// todo: support Cargo.toml | ||
} | ||
|
||
return nil, errors.New(fmt.Sprintf("no %s project found", EcosystemTitle())) | ||
} |
This file contains 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,19 @@ | ||
package cratesio | ||
|
||
import ( | ||
"cvepack/core/scan/files" | ||
"testing" | ||
) | ||
|
||
func Test_NewProjectFromProvider(t *testing.T) { | ||
provider := files.NewProviderFromPath("./testdata") | ||
project, err := NewProjectFromProvider(provider) | ||
|
||
if err != nil { | ||
t.Errorf("Expected no error, got %v", err) | ||
} | ||
|
||
if len(project.Packages()) != 180 { | ||
t.Errorf("Expected project to have 180 packages, got %d", len(project.Packages())) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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,7 @@ | ||
package golang | ||
|
||
import "cvepack/core/ecosystem" | ||
|
||
func NewProject(source ecosystem.Source, packages []ecosystem.Package) ecosystem.Project { | ||
return ecosystem.NewProject(source.Value, EcosystemName, packages) | ||
} |
Oops, something went wrong.