-
Notifications
You must be signed in to change notification settings - Fork 44
/
providers.go
54 lines (46 loc) · 2.23 KB
/
providers.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
package stereoscope
import (
"github.com/anchore/go-collections"
containerdClient "github.com/anchore/stereoscope/internal/containerd"
"github.com/anchore/stereoscope/pkg/image"
"github.com/anchore/stereoscope/pkg/image/containerd"
"github.com/anchore/stereoscope/pkg/image/docker"
"github.com/anchore/stereoscope/pkg/image/oci"
"github.com/anchore/stereoscope/pkg/image/podman"
"github.com/anchore/stereoscope/pkg/image/sif"
)
const (
FileTag = "file"
DirTag = "dir"
DaemonTag = "daemon"
PullTag = "pull"
RegistryTag = "registry"
)
// ImageProviderConfig is the user-configuration containing all configuration needed by stereoscope image providers
type ImageProviderConfig struct {
UserInput string
Platform *image.Platform
Registry image.RegistryOptions
}
func ImageProviders(cfg ImageProviderConfig) []collections.TaggedValue[image.Provider] {
tempDirGenerator := rootTempDirGenerator.NewGenerator()
return []collections.TaggedValue[image.Provider]{
// file providers
taggedProvider(docker.NewArchiveProvider(tempDirGenerator, cfg.UserInput), FileTag),
taggedProvider(oci.NewArchiveProvider(tempDirGenerator, cfg.UserInput), FileTag),
taggedProvider(oci.NewDirectoryProvider(tempDirGenerator, cfg.UserInput), FileTag, DirTag),
taggedProvider(sif.NewArchiveProvider(tempDirGenerator, cfg.UserInput), FileTag),
// daemon providers
taggedProvider(docker.NewDaemonProvider(tempDirGenerator, cfg.UserInput, cfg.Platform), DaemonTag, PullTag),
taggedProvider(podman.NewDaemonProvider(tempDirGenerator, cfg.UserInput, cfg.Platform), DaemonTag, PullTag),
taggedProvider(containerd.NewDaemonProvider(tempDirGenerator, cfg.Registry, containerdClient.Namespace(), cfg.UserInput, cfg.Platform), DaemonTag, PullTag),
// registry providers
taggedProvider(oci.NewRegistryProvider(tempDirGenerator, cfg.Registry, cfg.UserInput, cfg.Platform), RegistryTag, PullTag),
}
}
func taggedProvider(provider image.Provider, tags ...string) collections.TaggedValue[image.Provider] {
return collections.NewTaggedValue[image.Provider](provider, append([]string{provider.Name()}, tags...)...)
}
func allProviderTags() []string {
return collections.TaggedValueSet[image.Provider]{}.Join(ImageProviders(ImageProviderConfig{})...).Tags()
}