@@ -17,8 +17,6 @@ package ecosystem
1717
1818import (
1919 "errors"
20- "net/http"
21- "strings"
2220
2321 "github.com/google/osv-scalibr/semantic"
2422 "github.com/ossf/osv-schema/bindings/go/osvconstants"
@@ -28,77 +26,52 @@ var ErrCoarseNotSupported = errors.New("coarse version not supported")
2826var ErrVersionEcosystemMismatch = errors .New ("version ecosystem mismatch" )
2927var ErrPackageNotFound = errors .New ("package not found" )
3028
31- // HTTPClient is the global HTTP client used by ecosystems for fetching
32- // version information and other external data. It may be overridden for testing.
33- var HTTPClient = http .DefaultClient
29+ type ecosystemFactory func (p * Provider , suffix string ) Ecosystem
3430
35- // Get returns an ecosystem for the given ecosystem name.
36- // If the ecosystem is not found, it returns nil, false.
37- //
38- // The ecosystem name can optionally include a version suffix (e.g. "Debian:10").
39- func Get (ecosystem string ) (Ecosystem , bool ) {
40- name , suffix , _ := strings .Cut (ecosystem , ":" )
41- f , ok := ecosystems [osvconstants .Ecosystem (name )]
42- if ! ok {
43- return nil , false
44- }
45- // Wrap the ecosystem to handle "0" versions.
46- e := f (suffix )
47- if enum , ok := e .(Enumerable ); ok {
48- return & enumerableWrapper {Enumerable : enum }, true
49- }
50-
51- return & ecosystemWrapper {Ecosystem : e }, true
52- }
53-
54- type ecosystemFactory func (suffix string ) Ecosystem
55-
56- // statelessFactory returns a factory for the given ecosystem type that ignores the suffix
57- // and returns the zero value of E.
58- func statelessFactory [E Ecosystem ](_ string ) Ecosystem {
31+ func statelessFactory [E Ecosystem ](_ * Provider , _ string ) Ecosystem {
5932 var e E
6033 return e
6134}
6235
6336// debianFactory returns a factory that injects the release suffix.
64- func debianFactory (suffix string ) Ecosystem {
65- return debianEcosystem {release : suffix }
37+ func debianFactory (p * Provider , suffix string ) Ecosystem {
38+ return debianEcosystem {release : suffix , p : p }
6639}
6740
6841var ecosystems = map [osvconstants.Ecosystem ]ecosystemFactory {
6942 osvconstants .EcosystemAlmaLinux : statelessFactory [rpmEcosystem ],
7043 osvconstants .EcosystemAlpaquita : statelessFactory [apkEcosystem ],
7144 osvconstants .EcosystemAlpine : statelessFactory [apkEcosystem ],
7245 osvconstants .EcosystemBellSoftHardenedContainers : statelessFactory [apkEcosystem ],
73- osvconstants .EcosystemBioconductor : statelessFactory [ bioconductorEcosystem ] ,
46+ osvconstants .EcosystemBioconductor : func ( p * Provider , _ string ) Ecosystem { return bioconductorEcosystem { p : p } } ,
7447 osvconstants .EcosystemBitnami : statelessFactory [semverEcosystem ],
7548 osvconstants .EcosystemChainguard : statelessFactory [apkEcosystem ],
7649 osvconstants .EcosystemCleanStart : statelessFactory [apkEcosystem ],
77- osvconstants .EcosystemCRAN : statelessFactory [ cranEcosystem ] ,
50+ osvconstants .EcosystemCRAN : func ( p * Provider , _ string ) Ecosystem { return cranEcosystem { p : p } } ,
7851 osvconstants .EcosystemCratesIO : statelessFactory [semverEcosystem ],
7952 osvconstants .EcosystemDebian : debianFactory ,
8053 osvconstants .EcosystemDockerHardenedImages : statelessFactory [semverEcosystem ],
8154 osvconstants .EcosystemEcho : statelessFactory [dpkgEcosystem ],
82- osvconstants .EcosystemGHC : statelessFactory [ ghcEcosystem ] ,
55+ osvconstants .EcosystemGHC : func ( p * Provider , _ string ) Ecosystem { return ghcEcosystem { p : p } } ,
8356 osvconstants .EcosystemGo : statelessFactory [semverEcosystem ],
84- osvconstants .EcosystemHackage : statelessFactory [ hackageEcosystem ] ,
85- osvconstants .EcosystemHex : statelessFactory [ hexEcosystem ] ,
57+ osvconstants .EcosystemHackage : func ( p * Provider , _ string ) Ecosystem { return hackageEcosystem { p : p } } ,
58+ osvconstants .EcosystemHex : func ( p * Provider , _ string ) Ecosystem { return hexEcosystem { p : p } } ,
8659 osvconstants .EcosystemJulia : statelessFactory [semverEcosystem ],
8760 osvconstants .EcosystemMageia : statelessFactory [rpmEcosystem ],
88- osvconstants .EcosystemMaven : statelessFactory [ mavenEcosystem ] ,
61+ osvconstants .EcosystemMaven : func ( p * Provider , _ string ) Ecosystem { return mavenEcosystem { p : p } } ,
8962 osvconstants .EcosystemMinimOS : statelessFactory [apkEcosystem ],
9063 osvconstants .EcosystemNPM : statelessFactory [semverEcosystem ],
91- osvconstants .EcosystemNuGet : statelessFactory [ nugetEcosystem ] ,
64+ osvconstants .EcosystemNuGet : func ( p * Provider , _ string ) Ecosystem { return nugetEcosystem { p : p } } ,
9265 osvconstants .EcosystemOpam : statelessFactory [opamEcosystem ],
9366 osvconstants .EcosystemOpenEuler : statelessFactory [rpmEcosystem ],
9467 osvconstants .EcosystemOpenSUSE : statelessFactory [rpmEcosystem ],
95- osvconstants .EcosystemPackagist : statelessFactory [ packagistEcosystem ] ,
96- osvconstants .EcosystemPub : statelessFactory [ pubEcosystem ] ,
97- osvconstants .EcosystemPyPI : statelessFactory [ pyPIEcosystem ] ,
68+ osvconstants .EcosystemPackagist : func ( p * Provider , _ string ) Ecosystem { return packagistEcosystem { p : p } } ,
69+ osvconstants .EcosystemPub : func ( p * Provider , _ string ) Ecosystem { return pubEcosystem { p : p } } ,
70+ osvconstants .EcosystemPyPI : func ( p * Provider , _ string ) Ecosystem { return pypiEcosystem { p : p } } ,
9871 osvconstants .EcosystemRedHat : statelessFactory [rpmEcosystem ],
9972 osvconstants .EcosystemRockyLinux : statelessFactory [rpmEcosystem ],
10073 osvconstants .EcosystemRoot : rootEcosystemFactory ,
101- osvconstants .EcosystemRubyGems : statelessFactory [ rubyGemsEcosystem ] ,
74+ osvconstants .EcosystemRubyGems : func ( p * Provider , _ string ) Ecosystem { return rubyGemsEcosystem { p : p } } ,
10275 osvconstants .EcosystemSUSE : statelessFactory [rpmEcosystem ],
10376 osvconstants .EcosystemSwiftURL : statelessFactory [semverEcosystem ],
10477 osvconstants .EcosystemUbuntu : statelessFactory [dpkgEcosystem ],
0 commit comments