|
| 1 | +// Copyright 2022 Security Scorecard Authors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package dependencydiff |
| 16 | + |
| 17 | +import ( |
| 18 | + "fmt" |
| 19 | +) |
| 20 | + |
| 21 | +// Ecosystem is a package ecosystem supported by OSV, GitHub, etc. |
| 22 | +type ecosystem string |
| 23 | + |
| 24 | +// OSV ecosystem naming data source: https://ossf.github.io/osv-schema/#affectedpackage-field |
| 25 | +// nolint |
| 26 | +const ( |
| 27 | + // The Go ecosystem. |
| 28 | + ecosystemGo ecosystem = "Go" |
| 29 | + |
| 30 | + // The NPM ecosystem. |
| 31 | + ecosystemNpm ecosystem = "npm" |
| 32 | + |
| 33 | + // The Android ecosystem |
| 34 | + ecosystemAndroid ecosystem = "Android" // nolint:unused |
| 35 | + |
| 36 | + // The crates.io ecosystem for RUST. |
| 37 | + ecosystemCrates ecosystem = "crates.io" |
| 38 | + |
| 39 | + // For reports from the OSS-Fuzz project that have no more appropriate ecosystem. |
| 40 | + ecosystemOssFuzz ecosystem = "OSS-Fuzz" // nolint:unused |
| 41 | + |
| 42 | + // The Python PyPI ecosystem. PyPI is the main package source of pip. |
| 43 | + ecosystemPyPI ecosystem = "PyPI" |
| 44 | + |
| 45 | + // The RubyGems ecosystem. |
| 46 | + ecosystemRubyGems ecosystem = "RubyGems" |
| 47 | + |
| 48 | + // The PHP package manager ecosystem. Packagist is the main Composer repository. |
| 49 | + ecosystemPackagist ecosystem = "Packagist" |
| 50 | + |
| 51 | + // The Maven Java package ecosystem. |
| 52 | + ecosystemMaven ecosystem = "Maven" |
| 53 | + |
| 54 | + // The NuGet package ecosystem. |
| 55 | + ecosystemNuGet ecosystem = "Nuget" |
| 56 | + |
| 57 | + // The Linux kernel. |
| 58 | + ecosystemLinux ecosystem = "Linux" // nolint:unused |
| 59 | + |
| 60 | + // The Debian package ecosystem. |
| 61 | + ecosystemDebian ecosystem = "Debian" // nolint:unused |
| 62 | + |
| 63 | + // Hex is the package manager of Erlang. |
| 64 | + // TODO: GitHub doesn't support hex as the ecosystem for Erlang yet. Add this to the map in the future. |
| 65 | + ecosystemHex ecosystem = "Hex" // nolint:unused |
| 66 | +) |
| 67 | + |
| 68 | +var ( |
| 69 | + //gitHubToOSV defines the ecosystem naming mapping relationship between GitHub and others. |
| 70 | + gitHubToOSV = map[string]ecosystem{ |
| 71 | + // GitHub ecosystem naming data source: https://docs.github.com/en/code-security/supply-chain-security/ |
| 72 | + // understanding-your-software-supply-chain/about-the-dependency-graph#supported-package-ecosystems |
| 73 | + "gomod": ecosystemGo, /* go.mod and go.sum */ |
| 74 | + "cargo": ecosystemCrates, |
| 75 | + "pip": ecosystemPyPI, /* pip and poetry */ |
| 76 | + "npm": ecosystemNpm, /* npm and yarn */ |
| 77 | + "maven": ecosystemMaven, |
| 78 | + "composer": ecosystemPackagist, |
| 79 | + "rubygems": ecosystemRubyGems, |
| 80 | + "nuget": ecosystemNuGet, |
| 81 | + } |
| 82 | +) |
| 83 | + |
| 84 | +func toEcosystem(e string) (ecosystem, error) { |
| 85 | + if ecosystemOSV, found := gitHubToOSV[e]; found { |
| 86 | + return ecosystemOSV, nil |
| 87 | + } |
| 88 | + return "", fmt.Errorf("%w for github entry %s", errMappingNotFound, e) |
| 89 | +} |
0 commit comments