File: amazon.go

package info (click to toggle)
goval-dictionary 0.2.0-6
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 424 kB
  • sloc: makefile: 2
file content (60 lines) | stat: -rw-r--r-- 1,279 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package models

import (
	"fmt"
	"time"

	c "github.com/kotakanbe/goval-dictionary/config"
	"github.com/kotakanbe/goval-dictionary/fetcher"
)

// ConvertAmazonToModel Convert OVAL to models
func ConvertAmazonToModel(data *fetcher.UpdateInfo) (defs []Definition) {
	for _, alas := range data.ALASList {
		cves := []Cve{}
		for _, cveID := range alas.CVEIDs {
			cves = append(cves, Cve{CveID: cveID})
		}

		packs := []Package{}
		for _, pack := range alas.Packages {
			packs = append(packs, Package{
				Name: pack.Name,
				Version: fmt.Sprintf("%s:%s-%s",
					pack.Epoch, pack.Version, pack.Release),
				Arch: pack.Arch,
			})
		}
		updatedAt, _ := time.Parse("2006-01-02 15:04", alas.Updated.Date)

		refs := []Reference{}
		for _, ref := range alas.References {
			refs = append(refs, Reference{
				Source: ref.Type,
				RefID:  ref.ID,
				RefURL: ref.Href,
			})
		}

		def := Definition{
			DefinitionID:  "def-" + alas.ID,
			Title:         alas.ID,
			Description:   alas.Description,
			AffectedPacks: packs,
			Advisory: Advisory{
				Cves:     cves,
				Severity: alas.Severity,
				Updated:  updatedAt,
			},
			References: refs,
		}

		if c.Conf.NoDetails {
			def.Description = ""
			def.References = []Reference{}
		}

		defs = append(defs, def)
	}
	return
}