Repository navigation
Add disabled_ecosystems to turn ecosystems off #802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
simonchrz
wants to merge
1
commit into
git-pkgs:main
Choose a base branch
from
simonchrz:feat/disable-ecosystems
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,49 @@ | ||
| package config | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "slices" | ||
| "strings" | ||
| ) | ||
|
|
||
| // DisableableEcosystems are the ecosystem keys disabled_ecosystems accepts: | ||
| // the ones served by default. git and generic serve only what upstream.git | ||
| // and upstream.generic configure, so they are turned off by leaving those | ||
| // out. | ||
| var DisableableEcosystems = []string{ | ||
| "alpine", "arch", "cargo", "chef", "composer", "conan", "conda", "cran", "deb", | ||
| "freebsd", "gem", "golang", "gradle", "helm", "hex", "homebrew", "julia", "maven", | ||
| "npm", "nuget", "oci", "pub", "pypi", "rpm", "swift", "terraform", | ||
| } | ||
|
|
||
| // normalizeEcosystem resolves case and the aliases scanning accepts, plus | ||
| // brew for homebrew. | ||
| func normalizeEcosystem(name string) string { | ||
| key := NormalizeScannerEcosystem(name) | ||
| if key == "brew" { | ||
| return "homebrew" | ||
| } | ||
| return key | ||
| } | ||
|
|
||
| // validateDisabledEcosystems normalizes disabled_ecosystems in place and | ||
| // rejects names it doesn't accept. | ||
| func (c *Config) validateDisabledEcosystems() error { | ||
| for i, name := range c.DisabledEcosystems { | ||
| key := normalizeEcosystem(name) | ||
| if !slices.Contains(DisableableEcosystems, key) { | ||
| return fmt.Errorf("invalid disabled_ecosystems entry %q (valid: %s)", name, strings.Join(DisableableEcosystems, ", ")) | ||
| } | ||
| c.DisabledEcosystems[i] = key | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // EcosystemDisabled reports whether disabled_ecosystems turns off the | ||
| // ecosystem, given by its key or an alias such as apk, go or docker. | ||
| func (c *Config) EcosystemDisabled(name string) bool { | ||
| key := normalizeEcosystem(name) | ||
| return slices.ContainsFunc(c.DisabledEcosystems, func(entry string) bool { | ||
| return normalizeEcosystem(entry) == key | ||
| }) | ||
| } |
This file contains hidden or 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,74 @@ | ||
| package config | ||
|
|
||
| import ( | ||
| "slices" | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestDisabledEcosystemsDefaultToNone(t *testing.T) { | ||
| cfg := Default() | ||
| if err := cfg.Validate(); err != nil { | ||
| t.Fatalf("Validate: %v", err) | ||
| } | ||
| for _, key := range DisableableEcosystems { | ||
| if cfg.EcosystemDisabled(key) { | ||
| t.Errorf("%s is disabled by default", key) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestDisabledEcosystemsAreNormalized(t *testing.T) { | ||
| cfg := Default() | ||
| cfg.DisabledEcosystems = []string{"PyPI", " apk ", "go", "docker", "debian", "brew", "rubygems"} | ||
| if err := cfg.Validate(); err != nil { | ||
| t.Fatalf("Validate: %v", err) | ||
| } | ||
| want := []string{"pypi", "alpine", "golang", "oci", "deb", "homebrew", "gem"} | ||
| if !slices.Equal(cfg.DisabledEcosystems, want) { | ||
| t.Errorf("DisabledEcosystems = %v, want %v", cfg.DisabledEcosystems, want) | ||
| } | ||
| for _, name := range []string{"pypi", "PyPI", "alpine", "apk", "golang", "go", "oci", "docker", "deb", "homebrew", "brew", "gem"} { | ||
| if !cfg.EcosystemDisabled(name) { | ||
| t.Errorf("EcosystemDisabled(%q) = false, want true", name) | ||
| } | ||
| } | ||
| for _, name := range []string{"npm", "cargo", "maven"} { | ||
| if cfg.EcosystemDisabled(name) { | ||
| t.Errorf("EcosystemDisabled(%q) = true, want false", name) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestDisabledEcosystemsRejectUnknownNames(t *testing.T) { | ||
| for _, name := range []string{"pipy", "git", "generic", ""} { | ||
| cfg := Default() | ||
| cfg.DisabledEcosystems = []string{"npm", name} | ||
| err := cfg.Validate() | ||
| if err == nil { | ||
| t.Errorf("%q: Validate accepted it", name) | ||
| continue | ||
| } | ||
| if !strings.Contains(err.Error(), "disabled_ecosystems") { | ||
| t.Errorf("%q: error %q doesn't name the setting", name, err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestDisabledEcosystemsFromEnv(t *testing.T) { | ||
| t.Setenv("PROXY_DISABLED_ECOSYSTEMS", "pypi, cargo") | ||
| cfg := Default() | ||
| cfg.LoadFromEnv() | ||
| if !slices.Equal(cfg.DisabledEcosystems, []string{"pypi", "cargo"}) { | ||
| t.Errorf("DisabledEcosystems = %v, want [pypi cargo]", cfg.DisabledEcosystems) | ||
| } | ||
| } | ||
|
|
||
| // Entries are matched by key before Validate has normalized them too. | ||
| func TestEcosystemDisabledBeforeValidate(t *testing.T) { | ||
| cfg := Default() | ||
| cfg.DisabledEcosystems = []string{"PyPI", "apk"} | ||
| if !cfg.EcosystemDisabled("pypi") || !cfg.EcosystemDisabled("alpine") || cfg.EcosystemDisabled("npm") { | ||
| t.Errorf("EcosystemDisabled doesn't match unnormalized entries") | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skip disabled unversioned PURLs before version listing.
With npm disabled, an unversioned PURL such as
pkg:npm/lodashstill lists its versions from upstream.PURLSource.Enumerateruns this listing beforeRunstarts any worker. If the listing fails,Runreturns an error and the whole job stops. Enabled inputs in the same job, such aspkg:cargo/serde@1.0.0, are not mirrored. The disabled package also does not record its "turned off" failure.Add a
Disabledpredicate toPURLSource. Check it beforelistVersions. For a disabled PURL, yield one item with no version.mirrorOnethen records the failure without fetching. Set the predicate at each place that builds aPURLSource:internal/mirror/job.go:214,internal/mirror/schedule.go:112, andcmd/proxy/main.go:484. Forward it inSBOMSource.Enumerateatinternal/mirror/source.go:195.Suggested fix
type PURLSource struct { PURLs []string // Versions lists the versions of unversioned PURLs. Nil lists them from // the public registries. Versions VersionLister // Latest mirrors only the newest version of unversioned PURLs. Latest bool // Platforms limit which platforms of container images are mirrored. Platforms []string + // Disabled reports whether an ecosystem is turned off. Nil turns none off. + Disabled func(ecosystem string) bool }