-
Notifications
You must be signed in to change notification settings - Fork 571
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: extract username as vendor candidate from github/gitlab
Signed-off-by: Weston Steimel <weston.steimel@anchore.com>
- Loading branch information
1 parent
187c745
commit ac012d9
Showing
2 changed files
with
50 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,56 @@ | ||
package cpe | ||
|
||
import ( | ||
"regexp" | ||
"strings" | ||
|
||
"github.com/anchore/syft/internal" | ||
) | ||
|
||
var ( | ||
urlPrefixVendors = map[string][]string{ | ||
urlPrefixToVendors = map[string][]string{ | ||
"https://www.gnu.org/": {"gnu"}, | ||
"https://developer.gnome.org/": {"gnome"}, | ||
"https://www.ruby-lang.org/": {"ruby-lang"}, | ||
"https://llvm.org/": {"llvm"}, | ||
"https://www.isc.org/": {"isc"}, | ||
} | ||
|
||
vendorExtractionPatterns = []*regexp.Regexp{ | ||
regexp.MustCompile(`^https://(?:github|gitlab)\.com/(?P<vendor>[\w\-]*?)/.*$`), | ||
} | ||
) | ||
|
||
func candidateVendorsFromURL(url string) fieldCandidateSet { | ||
vendors := newFieldCandidateSet() | ||
|
||
for urlPrefix, additionalVendors := range urlPrefixVendors { | ||
for urlPrefix, additionalVendors := range urlPrefixToVendors { | ||
if strings.HasPrefix(url, urlPrefix) { | ||
for _, v := range additionalVendors { | ||
vendors.add(fieldCandidate{ | ||
value: v, | ||
disallowSubSelections: true, | ||
disallowDelimiterVariations: true, | ||
}) | ||
|
||
return vendors | ||
} | ||
} | ||
} | ||
|
||
for _, p := range vendorExtractionPatterns { | ||
groups := internal.MatchNamedCaptureGroups(p, url) | ||
|
||
if v, ok := groups["vendor"]; ok { | ||
vendors.add(fieldCandidate{ | ||
value: v, | ||
disallowSubSelections: true, | ||
disallowDelimiterVariations: true, | ||
}) | ||
|
||
return vendors | ||
} | ||
} | ||
|
||
return vendors | ||
} |
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