-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Gareth Jones <[email protected]>
- Loading branch information
Showing
4 changed files
with
295 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package constants | ||
|
||
type Ecosystem string | ||
|
||
const ( | ||
EcosystemGo Ecosystem = "Go" | ||
EcosystemNPM Ecosystem = "npm" | ||
EcosystemOSSFuzz Ecosystem = "OSS-Fuzz" | ||
EcosystemPyPI Ecosystem = "PyPI" | ||
EcosystemRubyGems Ecosystem = "RubyGems" | ||
EcosystemCratesIO Ecosystem = "crates.io" | ||
EcosystemPackagist Ecosystem = "Packagist" | ||
EcosystemMaven Ecosystem = "Maven" | ||
EcosystemNuGet Ecosystem = "NuGet" | ||
EcosystemLinux Ecosystem = "Linux" | ||
EcosystemDebian Ecosystem = "Debian" | ||
EcosystemAlpine Ecosystem = "Alpine" | ||
EcosystemHex Ecosystem = "Hex" | ||
EcosystemAndroid Ecosystem = "Android" | ||
EcosystemGitHubActions Ecosystem = "GitHub Actions" | ||
EcosystemPub Ecosystem = "Pub" | ||
EcosystemConanCenter Ecosystem = "ConanCenter" | ||
EcosystemRockyLinux Ecosystem = "Rocky Linux" | ||
EcosystemAlmaLinux Ecosystem = "AlmaLinux" | ||
EcosystemBitnami Ecosystem = "Bitnami" | ||
EcosystemPhotonOS Ecosystem = "Photon OS" | ||
EcosystemCRAN Ecosystem = "CRAN" | ||
EcosystemBioconductor Ecosystem = "Bioconductor" | ||
EcosystemSwiftURL Ecosystem = "SwiftURL" | ||
EcosystemRedHat Ecosystem = "Red Hat" | ||
EcosystemUbuntu Ecosystem = "Ubuntu" | ||
) | ||
|
||
type SeverityType string | ||
|
||
const ( | ||
SeverityCVSSV2 SeverityType = "CVSS_V2" | ||
SeverityCVSSV3 SeverityType = "CVSS_V3" | ||
SeverityCVSSV4 SeverityType = "CVSS_V4" | ||
) | ||
|
||
type RangeType string | ||
|
||
const ( | ||
RangeSemVer RangeType = "SEMVER" | ||
RangeEcosystem RangeType = "ECOSYSTEM" | ||
RangeGit RangeType = "GIT" | ||
) | ||
|
||
type ReferenceType string | ||
|
||
const ( | ||
ReferenceAdvisory ReferenceType = "ADVISORY" | ||
ReferenceArticle ReferenceType = "ARTICLE" | ||
ReferenceDetection ReferenceType = "DETECTION" | ||
ReferenceDiscussion ReferenceType = "DISCUSSION" | ||
ReferenceReport ReferenceType = "REPORT" | ||
ReferenceFix ReferenceType = "FIX" | ||
ReferenceIntroduced ReferenceType = "INTRODUCED" | ||
ReferencePackage ReferenceType = "PACKAGE" | ||
ReferenceEvidence ReferenceType = "EVIDENCE" | ||
ReferenceWeb ReferenceType = "WEB" | ||
) | ||
|
||
type CreditType string | ||
|
||
const ( | ||
CreditFinder CreditType = "FINDER" | ||
CreditReporter CreditType = "REPORTER" | ||
CreditAnalyst CreditType = "ANALYST" | ||
CreditCoordinator CreditType = "COORDINATOR" | ||
CreditRemediationDeveloper CreditType = "REMEDIATION_DEVELOPER" //nolint:gosec | ||
CreditRemediationReviewer CreditType = "REMEDIATION_REVIEWER" //nolint:gosec | ||
CreditRemediationVerifier CreditType = "REMEDIATION_VERIFIER" //nolint:gosec | ||
CreditTool CreditType = "TOOL" | ||
CreditSponsor CreditType = "SPONSOR" | ||
CreditOther CreditType = "OTHER" | ||
) |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package ecosystem | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/ossf/osv-schema/constants" | ||
) | ||
|
||
type Parsed struct { | ||
Ecosystem constants.Ecosystem | ||
Suffix string | ||
} | ||
|
||
func (p *Parsed) String() string { | ||
str := string(p.Ecosystem) | ||
|
||
if p.Suffix != "" { | ||
str += ":" + p.Suffix | ||
} | ||
|
||
return str | ||
} | ||
|
||
// Parse parses a string into a constants.Ecosystem and an optional suffix specified with a ":" | ||
func Parse(str string) Parsed { | ||
ecosystem, suffix, _ := strings.Cut(str, ":") | ||
|
||
return Parsed{constants.Ecosystem(ecosystem), suffix} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,185 @@ | ||
package ecosystem_test | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/ossf/osv-schema/constants" | ||
"github.com/ossf/osv-schema/ecosystem" | ||
) | ||
|
||
type testCase struct { | ||
string string | ||
parsed ecosystem.Parsed | ||
} | ||
|
||
func buildCases() []testCase { | ||
return []testCase{ | ||
{ | ||
string: "crates.io", | ||
parsed: ecosystem.Parsed{ | ||
Ecosystem: constants.EcosystemCratesIO, | ||
Suffix: "", | ||
}, | ||
}, | ||
{ | ||
string: "crates.io: ", | ||
parsed: ecosystem.Parsed{ | ||
Ecosystem: constants.EcosystemCratesIO, | ||
Suffix: " ", | ||
}, | ||
}, | ||
{ | ||
string: "crates.io::", | ||
parsed: ecosystem.Parsed{ | ||
Ecosystem: constants.EcosystemCratesIO, | ||
Suffix: ":", | ||
}, | ||
}, | ||
{ | ||
string: "npm", | ||
parsed: ecosystem.Parsed{ | ||
Ecosystem: constants.EcosystemNPM, | ||
Suffix: "", | ||
}, | ||
}, | ||
{ | ||
string: "npm:abc", | ||
parsed: ecosystem.Parsed{ | ||
Ecosystem: constants.EcosystemNPM, | ||
Suffix: "abc", | ||
}, | ||
}, | ||
{ | ||
string: "Alpine", | ||
parsed: ecosystem.Parsed{ | ||
Ecosystem: constants.EcosystemAlpine, | ||
Suffix: "", | ||
}, | ||
}, | ||
{ | ||
string: "Alpine:v", | ||
parsed: ecosystem.Parsed{ | ||
Ecosystem: constants.EcosystemAlpine, | ||
Suffix: "v", | ||
}, | ||
}, | ||
{ | ||
string: "Alpine:v3.16", | ||
parsed: ecosystem.Parsed{ | ||
Ecosystem: constants.EcosystemAlpine, | ||
Suffix: "v3.16", | ||
}, | ||
}, | ||
{ | ||
string: "Alpine:3.16", | ||
parsed: ecosystem.Parsed{ | ||
Ecosystem: constants.EcosystemAlpine, | ||
Suffix: "3.16", | ||
}, | ||
}, | ||
{ | ||
string: "Maven", | ||
parsed: ecosystem.Parsed{ | ||
Ecosystem: constants.EcosystemMaven, | ||
Suffix: "", | ||
}, | ||
}, | ||
{ | ||
string: "Maven:https://maven.google.com", | ||
parsed: ecosystem.Parsed{ | ||
Ecosystem: constants.EcosystemMaven, | ||
Suffix: "https://maven.google.com", | ||
}, | ||
}, | ||
{ | ||
string: "Photon OS", | ||
parsed: ecosystem.Parsed{ | ||
Ecosystem: constants.EcosystemPhotonOS, | ||
Suffix: "", | ||
}, | ||
}, | ||
{ | ||
string: "Photon OS:abc", | ||
parsed: ecosystem.Parsed{ | ||
Ecosystem: constants.EcosystemPhotonOS, | ||
Suffix: "abc", | ||
}, | ||
}, | ||
{ | ||
string: "Photon OS:3.0", | ||
parsed: ecosystem.Parsed{ | ||
Ecosystem: constants.EcosystemPhotonOS, | ||
Suffix: "3.0", | ||
}, | ||
}, | ||
{ | ||
string: "Red Hat", | ||
parsed: ecosystem.Parsed{ | ||
Ecosystem: constants.EcosystemRedHat, | ||
Suffix: "", | ||
}, | ||
}, | ||
{ | ||
string: "Red Hat:abc", | ||
parsed: ecosystem.Parsed{ | ||
Ecosystem: constants.EcosystemRedHat, | ||
Suffix: "abc", | ||
}, | ||
}, | ||
{ | ||
string: "Red Hat:rhel_aus:8.4::appstream", | ||
parsed: ecosystem.Parsed{ | ||
Ecosystem: constants.EcosystemRedHat, | ||
Suffix: "rhel_aus:8.4::appstream", | ||
}, | ||
}, | ||
{ | ||
string: "Ubuntu", | ||
parsed: ecosystem.Parsed{ | ||
Ecosystem: constants.EcosystemUbuntu, | ||
Suffix: "", | ||
}, | ||
}, | ||
{ | ||
string: "Ubuntu:Pro", | ||
parsed: ecosystem.Parsed{ | ||
Ecosystem: constants.EcosystemUbuntu, | ||
Suffix: "Pro", | ||
}, | ||
}, | ||
{ | ||
string: "Ubuntu:Pro:18.04:LTS", | ||
parsed: ecosystem.Parsed{ | ||
Ecosystem: constants.EcosystemUbuntu, | ||
Suffix: "Pro:18.04:LTS", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func TestParsed_String(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := buildCases() | ||
for _, tt := range tests { | ||
t.Run(tt.string, func(t *testing.T) { | ||
if got := tt.parsed.String(); got != tt.string { | ||
t.Errorf("String() = %v, want %v", got, tt.string) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestParse(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := buildCases() | ||
for _, tt := range tests { | ||
t.Run(tt.string, func(t *testing.T) { | ||
if got := ecosystem.Parse(tt.string); !reflect.DeepEqual(got, tt.parsed) { | ||
t.Errorf("Parse() = %v, want %v", got, tt.parsed) | ||
} | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/ossf/osv-schema | ||
|
||
go 1.22.7 |