Skip to content

Commit

Permalink
- Added more safeguards and comments to the private getDefaultProvide…
Browse files Browse the repository at this point in the history
…rs() function in syft/pkg/cataloger/dotnet.
  • Loading branch information
HeyeOpenSource committed Oct 15, 2024
1 parent 68fbe0c commit c75d7b6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion syft/pkg/cataloger/dotnet/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ func getDefaultProviders() string {
packageSource := strings.TrimSpace(line[2:])
if strings.HasPrefix(packageSource, "https://") {
found := false
for _, knownSource := range packageSources {
if packageSource == knownSource {
found = true
}
}
if !found {
packageSources = append(packageSources, packageSource)
}
Expand All @@ -119,13 +124,19 @@ func getDefaultProviders() string {
cancel()
if len(packageSources) > 0 {
providers := []string{}
httpClient := &http.Client{
Timeout: time.Second * 5,
}
for _, packageSource := range packageSources {
if response, err := http.Get(packageSource); err == nil && response.StatusCode == http.StatusOK {
// Test the availability of the external package providers
if response, err := httpClient.Get(packageSource); err == nil && response.StatusCode == http.StatusOK {
apiData, err := io.ReadAll(response.Body)
response.Body.Close()

if err == nil {
api := sourceApi{}
if err = json.Unmarshal(apiData, &api); err == nil {
// Find all (NuGet) package resources of the API
for _, apiResource := range api.Resources {
if strings.HasSuffix(apiResource.ID, "/package") {
providers = append(providers, apiResource.ID)
Expand Down

0 comments on commit c75d7b6

Please sign in to comment.