github.com/anchore/syft@v1.38.2/syft/source/snapsource/snap_source_provider.go (about) 1 package snapsource 2 3 import ( 4 "context" 5 "crypto" 6 7 "github.com/anchore/syft/syft/source" 8 ) 9 10 type snapSourceProvider struct { 11 local bool 12 path string 13 exclude source.ExcludeConfig 14 digestAlgorithms []crypto.Hash 15 alias source.Alias 16 } 17 18 // NewLocalSourceProvider creates a new provider for snap files from a local path. 19 func NewLocalSourceProvider(path string, exclude source.ExcludeConfig, digestAlgorithms []crypto.Hash, alias source.Alias) source.Provider { 20 return &snapSourceProvider{ 21 local: true, 22 path: path, 23 exclude: exclude, 24 digestAlgorithms: digestAlgorithms, 25 alias: alias, 26 } 27 } 28 29 // NewRemoteSourceProvider creates a new provider for snap files from a remote location. 30 func NewRemoteSourceProvider(path string, exclude source.ExcludeConfig, digestAlgorithms []crypto.Hash, alias source.Alias) source.Provider { 31 return &snapSourceProvider{ 32 path: path, 33 exclude: exclude, 34 digestAlgorithms: digestAlgorithms, 35 alias: alias, 36 } 37 } 38 39 func (p snapSourceProvider) Name() string { 40 return "snap" 41 } 42 43 func (p snapSourceProvider) Provide(_ context.Context) (source.Source, error) { 44 cfg := Config{ 45 Request: p.path, 46 Exclude: p.exclude, 47 DigestAlgorithms: p.digestAlgorithms, 48 Alias: p.alias, 49 } 50 if p.local { 51 return NewFromLocal(cfg) 52 } 53 return NewFromRemote(cfg) 54 }