Skip to content

Commit c463400

Browse files
authored
refactor: order ecosystem stuff alphabetically (#390)
This should hopefully make it a bit easier to find stuff especially as support for more ecosystems is added Signed-off-by: Gareth Jones <[email protected]>
1 parent 1689eda commit c463400

File tree

4 files changed

+190
-190
lines changed

4 files changed

+190
-190
lines changed

tools/osv-linter/internal/pkgchecker/ecosystems.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,30 @@ import (
66

77
// Ecosystem support is a work in progress.
88
var SupportedEcosystems = []string{
9-
"Go",
10-
"PyPI",
119
"crates.io",
10+
"Go",
11+
"Hackage",
12+
"Maven",
1213
"npm",
1314
"NuGet",
14-
"RubyGems",
1515
"Packagist",
1616
"Pub",
17-
"Hackage",
18-
"Maven",
17+
"PyPI",
18+
"RubyGems",
1919
}
2020

2121
// EcosystemBaseURLs maps ecosystems to their base API URLs.
2222
var EcosystemBaseURLs = map[string]string{
23-
"Go": "https://proxy.golang.org",
24-
"PyPI": "https://pypi.org/pypi",
2523
"crates.io": "https://crates.io/api/v1/crates",
24+
"Go": "https://proxy.golang.org",
25+
"Hackage": "https://hackage.haskell.org/package",
26+
"Maven": "https://search.maven.org/solrsearch/select",
2627
"npm": "https://registry.npmjs.org",
2728
"NuGet": "https://api.nuget.org/v3-flatcontainer",
28-
"RubyGems": "https://rubygems.org/api/v1",
2929
"Packagist": "https://repo.packagist.org/p2",
3030
"Pub": "https://pub.dev/api/packages",
31-
"Hackage": "https://hackage.haskell.org/package",
32-
"Maven": "https://search.maven.org/solrsearch/select",
31+
"PyPI": "https://pypi.org/pypi",
32+
"RubyGems": "https://rubygems.org/api/v1",
3333
}
3434

3535
// Dispatcher for ecosystem-specific package existence checking.

tools/osv-linter/internal/pkgchecker/ecosystems_test.go

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ package pkgchecker
22

33
import "testing"
44

5-
func Test_versionsExistInRubyGems(t *testing.T) {
6-
t.Parallel()
7-
5+
func Test_versionsExistInGo(t *testing.T) {
86
type args struct {
97
pkg string
108
versions []string
@@ -15,44 +13,26 @@ func Test_versionsExistInRubyGems(t *testing.T) {
1513
wantErr bool
1614
}{
1715
{
18-
name: "multiple_versions_which_all_exist",
16+
name: "an unreleased package",
1917
args: args{
20-
pkg: "capistrano",
21-
versions: []string{"2.5.7", "3.0.0.pre4", "3.11.1"},
18+
pkg: "github.com/nanobox-io/golang-nanoauth",
19+
versions: nil,
2220
},
2321
wantErr: false,
2422
},
2523
{
26-
name: "multiple_versions_with_one_that_does_not_exist",
27-
args: args{
28-
pkg: "capistrano",
29-
versions: []string{"1.1.1", "2.3rc9", "3.1.5", "5.1rc1"},
30-
},
31-
wantErr: true,
32-
},
33-
{
34-
name: "an_invalid_version",
35-
args: args{
36-
pkg: "capistrano",
37-
versions: []string{"!"},
38-
},
39-
wantErr: true,
40-
},
41-
{
42-
name: "a_package_that_does_not_exit",
24+
name: "a released package",
4325
args: args{
44-
pkg: "not-a-real-package",
45-
versions: []string{"1.0.0"},
26+
pkg: "github.com/oauth2-proxy/oauth2-proxy",
27+
versions: []string{"1.1.1"},
4628
},
47-
wantErr: true,
29+
wantErr: false,
4830
},
4931
}
5032
for _, tt := range tests {
5133
t.Run(tt.name, func(t *testing.T) {
52-
t.Parallel()
53-
54-
if err := versionsExistInRubyGems(tt.args.pkg, tt.args.versions); (err != nil) != tt.wantErr {
55-
t.Errorf("versionsExistInRubyGems() error = %v, wantErr %v", err, tt.wantErr)
34+
if err := versionsExistInGo(tt.args.pkg, tt.args.versions); (err != nil) != tt.wantErr {
35+
t.Errorf("versionsExistInGo() error = %v, wantErr %v", err, tt.wantErr)
5636
}
5737
})
5838
}
@@ -186,7 +166,9 @@ func Test_versionsExistInPyPI(t *testing.T) {
186166
}
187167
}
188168

189-
func Test_versionsExistInGo(t *testing.T) {
169+
func Test_versionsExistInRubyGems(t *testing.T) {
170+
t.Parallel()
171+
190172
type args struct {
191173
pkg string
192174
versions []string
@@ -197,26 +179,44 @@ func Test_versionsExistInGo(t *testing.T) {
197179
wantErr bool
198180
}{
199181
{
200-
name: "an unreleased package",
182+
name: "multiple_versions_which_all_exist",
201183
args: args{
202-
pkg: "github.com/nanobox-io/golang-nanoauth",
203-
versions: nil,
184+
pkg: "capistrano",
185+
versions: []string{"2.5.7", "3.0.0.pre4", "3.11.1"},
204186
},
205187
wantErr: false,
206188
},
207189
{
208-
name: "a released package",
190+
name: "multiple_versions_with_one_that_does_not_exist",
209191
args: args{
210-
pkg: "github.com/oauth2-proxy/oauth2-proxy",
211-
versions: []string{"1.1.1"},
192+
pkg: "capistrano",
193+
versions: []string{"1.1.1", "2.3rc9", "3.1.5", "5.1rc1"},
212194
},
213-
wantErr: false,
195+
wantErr: true,
196+
},
197+
{
198+
name: "an_invalid_version",
199+
args: args{
200+
pkg: "capistrano",
201+
versions: []string{"!"},
202+
},
203+
wantErr: true,
204+
},
205+
{
206+
name: "a_package_that_does_not_exit",
207+
args: args{
208+
pkg: "not-a-real-package",
209+
versions: []string{"1.0.0"},
210+
},
211+
wantErr: true,
214212
},
215213
}
216214
for _, tt := range tests {
217215
t.Run(tt.name, func(t *testing.T) {
218-
if err := versionsExistInGo(tt.args.pkg, tt.args.versions); (err != nil) != tt.wantErr {
219-
t.Errorf("versionsExistInGo() error = %v, wantErr %v", err, tt.wantErr)
216+
t.Parallel()
217+
218+
if err := versionsExistInRubyGems(tt.args.pkg, tt.args.versions); (err != nil) != tt.wantErr {
219+
t.Errorf("versionsExistInRubyGems() error = %v, wantErr %v", err, tt.wantErr)
220220
}
221221
})
222222
}

tools/osv-linter/internal/pkgchecker/package_check.go

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,37 @@ func existsInGo(pkg string) bool {
4848
return checkPackageExists(packageInstanceURL)
4949
}
5050

51+
// Validate the existence of a package in Hackage.
52+
func existsInHackage(pkg string) bool {
53+
packageInstanceURL := fmt.Sprintf("%s/%s", EcosystemBaseURLs["Hackage"], pkg)
54+
55+
return checkPackageExists(packageInstanceURL)
56+
}
57+
58+
// Validate the existence of a package in Maven.
59+
func existsInMaven(pkg string) bool {
60+
if !strings.Contains(pkg, ":") {
61+
return false
62+
}
63+
group_id := strings.Split(pkg, ":")[0]
64+
artifact_id := strings.Split(pkg, ":")[1]
65+
66+
ecosystem := "Maven"
67+
packageInstanceURL := fmt.Sprintf("%s/?q=g:%s%%20AND%%20a:%s", EcosystemBaseURLs[ecosystem], group_id, artifact_id)
68+
69+
if isPackageInDepsDev(ecosystem, pkg) {
70+
return true
71+
}
72+
73+
// Needs to use GET instead of HEAD for Maven
74+
resp, err := faulttolerant.Get(packageInstanceURL)
75+
if err != nil {
76+
return false
77+
}
78+
79+
return resp.StatusCode == http.StatusOK
80+
}
81+
5182
// Validate the existence of a package in npm.
5283
func existsInNpm(pkg string) bool {
5384
ecosystem := "npm"
@@ -72,16 +103,16 @@ func existsInNuget(pkg string) bool {
72103
return checkPackageExists(packageInstanceURL)
73104
}
74105

75-
// Validate the existence of a package in RubyGems.
76-
func existsInRubyGems(pkg string) bool {
77-
packageInstanceURL := fmt.Sprintf("%s/gems/%s.json", EcosystemBaseURLs["RubyGems"], pkg)
106+
// Validate the existence of a package in Packagist.
107+
func existsInPackagist(pkg string) bool {
108+
packageInstanceURL := fmt.Sprintf("%s/%s.json", EcosystemBaseURLs["Packagist"], pkg)
78109

79110
return checkPackageExists(packageInstanceURL)
80111
}
81112

82-
// Validate the existence of a package in Packagist.
83-
func existsInPackagist(pkg string) bool {
84-
packageInstanceURL := fmt.Sprintf("%s/%s.json", EcosystemBaseURLs["Packagist"], pkg)
113+
// Validate the existence of a package in Pub.
114+
func existsInPub(pkg string) bool {
115+
packageInstanceURL := fmt.Sprintf("%s/%s", EcosystemBaseURLs["Pub"], pkg)
85116

86117
return checkPackageExists(packageInstanceURL)
87118
}
@@ -98,44 +129,13 @@ func existsInPyPI(pkg string) bool {
98129
return checkPackageExists(packageInstanceURL)
99130
}
100131

101-
// Validate the existence of a package in Pub.
102-
func existsInPub(pkg string) bool {
103-
packageInstanceURL := fmt.Sprintf("%s/%s", EcosystemBaseURLs["Pub"], pkg)
104-
105-
return checkPackageExists(packageInstanceURL)
106-
}
107-
108-
// Validate the existence of a package in Hackage.
109-
func existsInHackage(pkg string) bool {
110-
packageInstanceURL := fmt.Sprintf("%s/%s", EcosystemBaseURLs["Hackage"], pkg)
132+
// Validate the existence of a package in RubyGems.
133+
func existsInRubyGems(pkg string) bool {
134+
packageInstanceURL := fmt.Sprintf("%s/gems/%s.json", EcosystemBaseURLs["RubyGems"], pkg)
111135

112136
return checkPackageExists(packageInstanceURL)
113137
}
114138

115-
// Validate the existence of a package in Maven.
116-
func existsInMaven(pkg string) bool {
117-
if !strings.Contains(pkg, ":") {
118-
return false
119-
}
120-
group_id := strings.Split(pkg, ":")[0]
121-
artifact_id := strings.Split(pkg, ":")[1]
122-
123-
ecosystem := "Maven"
124-
packageInstanceURL := fmt.Sprintf("%s/?q=g:%s%%20AND%%20a:%s", EcosystemBaseURLs[ecosystem], group_id, artifact_id)
125-
126-
if isPackageInDepsDev(ecosystem, pkg) {
127-
return true
128-
}
129-
130-
// Needs to use GET instead of HEAD for Maven
131-
resp, err := faulttolerant.Get(packageInstanceURL)
132-
if err != nil {
133-
return false
134-
}
135-
136-
return resp.StatusCode == http.StatusOK
137-
}
138-
139139
// Makes an HTTP GET request to check package existance, with fault tolerance.
140140
func checkPackageExists(packageInstanceURL string) bool {
141141
// This 404's for non-existent packages.

0 commit comments

Comments
 (0)