-
Notifications
You must be signed in to change notification settings - Fork 278
/
structured_bom_format.go
51 lines (41 loc) · 1.13 KB
/
structured_bom_format.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
package writer
import (
"fmt"
"github.com/buildpacks/pack/internal/style"
"github.com/buildpacks/pack/internal/inspectimage"
"github.com/buildpacks/pack"
"github.com/buildpacks/pack/logging"
)
type StructuredBOMFormat struct {
MarshalFunc func(interface{}) ([]byte, error)
}
func (w *StructuredBOMFormat) Print(
logger logging.Logger,
generalInfo inspectimage.GeneralInfo,
local, remote *pack.ImageInfo,
localErr, remoteErr error,
) error {
if local == nil && remote == nil {
return fmt.Errorf("unable to find image '%s' locally or remotely", generalInfo.Name)
}
if localErr != nil && remoteErr != nil {
return fmt.Errorf("preparing BOM output for %s: local :%s remote: %s", style.Symbol(generalInfo.Name), localErr, remoteErr)
}
out, err := w.MarshalFunc(inspectimage.BOMDisplay{
Remote: inspectimage.NewBOMDisplay(remote),
Local: inspectimage.NewBOMDisplay(local),
RemoteErr: errorString(remoteErr),
LocalErr: errorString(localErr),
})
if err != nil {
return err
}
_, err = logger.Writer().Write(out)
return err
}
func errorString(err error) string {
if err == nil {
return ""
}
return err.Error()
}