-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
flare_provider.go
40 lines (32 loc) · 1.34 KB
/
flare_provider.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
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
package workloadmeta
import (
"encoding/json"
"fmt"
flaretypes "github.com/DataDog/datadog-agent/comp/core/flare/types"
"github.com/samber/lo"
)
/*
This file contains the implementation of the flare providers for the workloadmeta component.
The flare providers are used to add additional data to the flare archive. They should be provided
with workloadmeta to dump its state.
*/
// sbomFlareProvider will add the SBOMs of all the images in the flare archive.
// Note that the generated file uncompressed can be very large
func (w *workloadmeta) sbomFlareProvider(fb flaretypes.FlareBuilder) error {
images := w.ListImages()
fields := lo.SliceToMap(images, func(image *ContainerImageMetadata) (string, *SBOM) {
return image.ID, image.SBOM
})
// Using indent or splitting the file is necessary. Otherwise the scrubber will understand
// the file as a single very large token and it will exceed the max buffer size.
content, err := json.MarshalIndent(fields, "", " ")
if err != nil {
return fmt.Errorf("failed to marshal results to JSON: %v", err)
}
_ = fb.AddFile("sbom.json", content)
return nil
}