-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathdaemon.go
58 lines (47 loc) · 1.1 KB
/
daemon.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 image
import (
"context"
"github.com/google/go-containerregistry/pkg/name"
"github.com/aquasecurity/trivy/pkg/fanal/image/daemon"
"github.com/aquasecurity/trivy/pkg/fanal/types"
)
func tryDockerDaemon(imageName string, ref name.Reference) (types.Image, func(), error) {
img, cleanup, err := daemon.DockerImage(ref)
if err != nil {
return nil, nil, err
}
return daemonImage{
Image: img,
name: imageName,
}, cleanup, nil
}
func tryPodmanDaemon(ref string) (types.Image, func(), error) {
img, cleanup, err := daemon.PodmanImage(ref)
if err != nil {
return nil, nil, err
}
return daemonImage{
Image: img,
name: ref,
}, cleanup, nil
}
func tryContainerdDaemon(ctx context.Context, imageName string) (types.Image, func(), error) {
img, cleanup, err := daemon.ContainerdImage(ctx, imageName)
if err != nil {
return nil, cleanup, err
}
return daemonImage{
Image: img,
name: imageName,
}, cleanup, nil
}
type daemonImage struct {
daemon.Image
name string
}
func (d daemonImage) Name() string {
return d.name
}
func (d daemonImage) ID() (string, error) {
return ID(d)
}