-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy patharchive.go
64 lines (52 loc) · 1.25 KB
/
archive.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
59
60
61
62
63
64
package image
import (
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/hashicorp/go-multierror"
"github.com/aquasecurity/trivy/pkg/fanal/types"
)
func NewArchiveImage(fileName string) (types.Image, error) {
img, err := newImage(fileName)
if err != nil {
return nil, err
}
return archiveImage{
name: fileName,
Image: img,
}, nil
}
func newImage(fileName string) (v1.Image, error) {
var errs error
// Docker archive
img, err := tryDockerArchive(fileName)
if err == nil {
// Return v1.Image if the file can be opened as Docker archive
return img, nil
}
errs = multierror.Append(errs, err)
// OCI layout
img, err = tryOCI(fileName)
if err == nil {
// Return v1.Image if the directory can be opened as OCI Image Format
return img, nil
}
errs = multierror.Append(errs, err)
return nil, errs
}
type archiveImage struct {
v1.Image
name string
}
func (img archiveImage) Name() string {
return img.name
}
func (img archiveImage) ID() (string, error) {
return ID(img)
}
// RepoTags returns empty as an archive doesn't support RepoTags
func (archiveImage) RepoTags() []string {
return nil
}
// RepoDigests returns empty as an archive doesn't support RepoDigests
func (archiveImage) RepoDigests() []string {
return nil
}