Skip to content
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

feat: build config can specify package CPE #1768

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,44 @@ type Package struct {
Scriptlets *Scriptlets `json:"scriptlets,omitempty" yaml:"scriptlets,omitempty"`
// Optional: enabling, disabling, and configuration of build checks
Checks Checks `json:"checks,omitempty" yaml:"checks,omitempty"`
// The CPE field values to be used for matching against NVD vulnerability
// records, if known.
CPE CPE `json:"cpe,omitempty" yaml:"cpe,omitempty"`

// Optional: The amount of time to allow this build to take before timing out.
Timeout time.Duration `json:"timeout,omitempty" yaml:"timeout,omitempty"`
// Optional: Resources to allocate to the build.
Resources *Resources `json:"resources,omitempty" yaml:"resources,omitempty"`
}

// CPE stores values used to produce a CPE to describe the package, suitable for
// matching against NVD records.
//
// For Melange, the "part" attribute should always be interpreted as "a" (for
// "application").
type CPE struct {
Vendor string
Product string
}

type Resources struct {
CPU string `json:"cpu,omitempty" yaml:"cpu,omitempty"`
CPUModel string `json:"cpumodel,omitempty" yaml:"cpumodel,omitempty"`
Memory string `json:"memory,omitempty" yaml:"memory,omitempty"`
Disk string `json:"disk,omitempty" yaml:"disk,omitempty"`
}

// CPEString returns the CPE string for the package, suitable for matching
// against NVD records.
func (p Package) CPEString() string {
return fmt.Sprintf(
"cpe:2.3:a:%s:%s:%s:*:*:*:*:*:*:*:*",
p.CPE.Vendor,
p.CPE.Product,
p.Version,
)
}

// PackageURL returns the package URL ("purl") for the APK (origin) package.
func (p Package) PackageURL(distro, arch string) *purl.PackageURL {
return newAPKPackageURL(distro, p.Name, p.FullVersion(), arch)
Expand Down Expand Up @@ -1168,6 +1192,7 @@ func replacePackage(r *strings.Replacer, commit string, in Package) Package {
Options: in.Options,
Scriptlets: replaceScriptlets(r, in.Scriptlets),
Checks: in.Checks,
CPE: in.CPE,
Timeout: in.Timeout,
Resources: in.Resources,
}
Expand Down
Loading