-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathimage_metadata.go
58 lines (52 loc) · 2.07 KB
/
image_metadata.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 source
import "github.com/anchore/syft/syft/source"
func ConvertImageMetadata(metadata source.ImageMetadata) ImageMetadata {
// TODO: (packit) Is there a cleaner way to unpack the new struct into the legacy one?
var layers []LayerMetadata
for _, l := range metadata.Layers {
layers = append(layers, LayerMetadata{
MediaType: l.MediaType,
Digest: l.Digest,
Size: l.Size,
})
}
// Create RepoDigests slice this way to ensure that it's encoded
// as an empty array (not null) if empty
repoDigests := make([]string, 0)
if metadata.RepoDigests != nil {
repoDigests = metadata.RepoDigests
}
return ImageMetadata{
UserInput: metadata.UserInput,
ID: metadata.ID,
ManifestDigest: metadata.ManifestDigest,
MediaType: metadata.MediaType,
Tags: metadata.Tags,
Size: metadata.Size,
Layers: layers,
RawManifest: metadata.RawManifest,
RawConfig: metadata.RawConfig,
RepoDigests: repoDigests,
}
}
// Source: https://github.com/anchore/syft/blob/dfefd2ea4e9d44187b4f861bc202970247dd34c8/syft/source/image_metadata.go
// ImageMetadata represents all static metadata that defines what a container image is. This is useful to later describe
// "what" was cataloged without needing the more complicated stereoscope Image objects or FileResolver objects.
type ImageMetadata struct {
UserInput string `json:"userInput"`
ID string `json:"imageID"`
ManifestDigest string `json:"manifestDigest"`
MediaType string `json:"mediaType"`
Tags []string `json:"tags"`
Size int64 `json:"imageSize"`
Layers []LayerMetadata `json:"layers"`
RawManifest []byte `json:"manifest"`
RawConfig []byte `json:"config"`
RepoDigests []string `json:"repoDigests"`
}
// LayerMetadata represents all static metadata that defines what a container image layer is.
type LayerMetadata struct {
MediaType string `json:"mediaType"`
Digest string `json:"digest"`
Size int64 `json:"size"`
}