func()

in providers/vfeed/schema/convert.go [181:238]


func (item *Item) configurationData() (*ProvidersConfiguration, error) {
	if item.Classification == nil {
		return nil, nil
	}

	config := ProvidersNewConfiguration()

	if item.Classification.Targets != nil {
		for _, target := range item.Classification.Targets {
			node := config.NewNode()

			// Parameters will follow one of the cases:
			// 1 - A list of vulnerable CPEs with versions
			// 2 - One vulnerable CPE with versions followed by "running_on",
			//     conditional non-vulnerable CPEs without versions.

			for _, params := range target.Parameters {
				if params.RunningOn != nil {
					for _, running := range params.RunningOn {
						node.AddConditionalMatch(
							&ProvidersMatch{
								CPE22URI:   running.CPE22,
								CPE23URI:   running.CPE23,
								Vulnerable: false,
							},
						)
					}

					continue
				}

				match := &ProvidersMatch{
					CPE22URI:   params.CPE22,
					CPE23URI:   params.CPE23,
					Vulnerable: true,
				}

				version := params.VersionAffected

				from, excluding, err := extractVersion(version.From)
				if err != nil {
					return nil, err
				}
				match.AddVersionStart(from, excluding)

				to, excluding, err := extractVersion(version.To)
				if err != nil {
					return nil, err
				}
				match.AddVersionEnd(to, excluding)

				node.AddMatch(match)
			}
		}
	}

	return config, nil
}