Esempio n. 1
0
// saveFields appends cayley's Save method to a path for each field in
// selectedFields, except the ones that appears also in exceptFields
func saveFields(p *path.Path, selectedFields []string, exceptFields []string) {
	for _, selectedField := range selectedFields {
		if utils.Contains(selectedField, exceptFields) {
			continue
		}
		p = p.Save(selectedField, selectedField)
	}
}
Esempio n. 2
0
// FindAllVulnerabilitiesByFixedIn finds and returns all vulnerabilities that are fixed in the given packages (speficied by their nodes), selecting the specified fields
func FindAllVulnerabilitiesByFixedIn(nodes []string, selectedFields []string) ([]*Vulnerability, error) {
	if len(nodes) == 0 {
		log.Warning("Could not FindAllVulnerabilitiesByFixedIn with an empty nodes array.")
		return []*Vulnerability{}, nil
	}

	// Construct path, potentially saving FieldVulnerabilityCausedByPackage
	path := cayley.StartPath(store, nodes...)
	if utils.Contains(FieldVulnerabilityCausedByPackage, selectedFields) {
		path = path.Save(FieldPackageName, FieldVulnerabilityCausedByPackage)
	}
	path = path.In(FieldVulnerabilityFixedIn)

	return toVulnerabilities(path, selectedFields)
}
Esempio n. 3
0
// mergeVulnerability updates the target vulnerability structure using the specified one.
func mergeVulnerability(target, source *database.Vulnerability) {
	if source.Link != "" {
		target.Link = source.Link
	}
	if source.Description != "" {
		target.Description = source.Description
	}
	if source.Priority.Compare(target.Priority) > 0 {
		target.Priority = source.Priority
	}
	for _, node := range source.FixedInNodes {
		if !utils.Contains(node, target.FixedInNodes) {
			target.FixedInNodes = append(target.FixedInNodes, node)
		}
	}
}
Esempio n. 4
0
// PreviousVersions find and returns all the packages of the same branch that
// have a lower version number, selecting the specified fields
// It requires that FieldPackageNextVersion field has been selected on p
// The immediate lower version is listed first, and the special start-of-Branch
// package is last, p is not listed
func (p *Package) PreviousVersions(selectedFields []string) ([]*Package, error) {
	var previousVersions []*Package

	if !utils.Contains(FieldPackagePreviousVersion, selectedFields) {
		selectedFields = append(selectedFields, FieldPackagePreviousVersion)
	}

	previousVersion, err := p.PreviousVersion(selectedFields)
	if err != nil {
		return []*Package{}, err
	}
	if previousVersion != nil {
		previousVersions = append(previousVersions, previousVersion)

		previousPreviousVersions, err := previousVersion.PreviousVersions(selectedFields)
		if err != nil {
			return []*Package{}, err
		}
		previousVersions = append(previousVersions, previousPreviousVersions...)
	}

	return previousVersions, nil
}
Esempio n. 5
0
// NextVersions find and returns all the packages of the same branch that have
// a higher version number, selecting the specified fields
// It requires that FieldPackageNextVersion field has been selected on p
// The immediate higher version is listed first, and the special end-of-Branch package is last, p is not listed
func (p *Package) NextVersions(selectedFields []string) ([]*Package, error) {
	var nextVersions []*Package

	if !utils.Contains(FieldPackageNextVersion, selectedFields) {
		selectedFields = append(selectedFields, FieldPackageNextVersion)
	}

	nextVersion, err := p.NextVersion(selectedFields)
	if err != nil {
		return []*Package{}, err
	}
	if nextVersion != nil {
		nextVersions = append(nextVersions, nextVersion)

		nextNextVersions, err := nextVersion.NextVersions(selectedFields)
		if err != nil {
			return []*Package{}, err
		}
		nextVersions = append(nextVersions, nextNextVersions...)
	}

	return nextVersions, nil
}