mirror of
https://github.com/anchore/syft.git
synced 2026-11-01 15:06:36 +01:00
add content requested and refactor python cataloger to use it
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package source
|
||||
|
||||
import "sync"
|
||||
|
||||
type ContentRequester struct {
|
||||
request map[Location][]*FileData
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
func NewContentRequester(data ...*FileData) *ContentRequester {
|
||||
requester := &ContentRequester{
|
||||
request: make(map[Location][]*FileData),
|
||||
}
|
||||
for _, d := range data {
|
||||
requester.Add(d)
|
||||
}
|
||||
return requester
|
||||
}
|
||||
|
||||
func (b *ContentRequester) Add(data *FileData) {
|
||||
b.lock.Lock()
|
||||
defer b.lock.Unlock()
|
||||
b.request[data.Location] = append(b.request[data.Location], data)
|
||||
}
|
||||
|
||||
func (b *ContentRequester) Execute(resolver ContentResolver) error {
|
||||
b.lock.Lock()
|
||||
defer b.lock.Unlock()
|
||||
|
||||
var locations = make([]Location, len(b.request))
|
||||
idx := 0
|
||||
for l := range b.request {
|
||||
locations[idx] = l
|
||||
idx++
|
||||
}
|
||||
|
||||
response, err := resolver.MultipleFileContentsByLocation(locations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for l, contents := range response {
|
||||
for i := range b.request[l] {
|
||||
b.request[l][i].Contents = contents
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package source
|
||||
|
||||
type FileData struct {
|
||||
Location Location
|
||||
Contents string
|
||||
}
|
||||
Reference in New Issue
Block a user