forked from anchore/syft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.go
58 lines (53 loc) · 1.43 KB
/
package.go
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
package nix
import (
"github.com/anchore/packageurl-go"
"github.com/gsoc2/syft/syft/file"
"github.com/gsoc2/syft/syft/pkg"
)
func newNixStorePackage(storePath nixStorePath, locations ...file.Location) pkg.Package {
p := pkg.Package{
Name: storePath.name,
Version: storePath.version,
FoundBy: catalogerName,
Locations: file.NewLocationSet(locations...),
Type: pkg.NixPkg,
PURL: packageURL(storePath),
Metadata: pkg.NixStoreEntry{
OutputHash: storePath.outputHash,
Output: storePath.output,
},
}
p.SetID()
return p
}
func packageURL(storePath nixStorePath) string {
var qualifiers packageurl.Qualifiers
if storePath.output != "" {
// since there is no nix pURL type yet, this is a guess, however, it is reasonable to assume that
// if only a single output is installed the pURL should be able to express this.
qualifiers = append(qualifiers,
packageurl.Qualifier{
Key: "output",
Value: storePath.output,
},
)
}
if storePath.outputHash != "" {
// it's not immediately clear if the hash found in the store path should be encoded in the pURL
qualifiers = append(qualifiers,
packageurl.Qualifier{
Key: "outputhash",
Value: storePath.outputHash,
},
)
}
pURL := packageurl.NewPackageURL(
// TODO: nix pURL type has not been accepted yet (only proposed at this time)
"nix",
"",
storePath.name,
storePath.version,
qualifiers,
"")
return pURL.ToString()
}