Skip to content

Commit

Permalink
libindex: use new Configurable interfaces
Browse files Browse the repository at this point in the history
This exploded a bit into also refactoring the layerscanner, which is the
primary place where scanners are actually invoked.

Signed-off-by: Hank Donnay <hdonnay@redhat.com>
  • Loading branch information
hdonnay committed May 29, 2020
1 parent 11b4676 commit a0c9aaa
Show file tree
Hide file tree
Showing 7 changed files with 291 additions and 224 deletions.
54 changes: 43 additions & 11 deletions internal/indexer/ecosystem.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package indexer

import "context"
import (
"context"

"github.com/rs/zerolog"
)

// Ecosystems group together scanners and a Coalescer which are commonly used together.
//
Expand All @@ -17,7 +21,11 @@ type Ecosystem struct {
}

// EcosystemsToScanners extracts and dedupes multiple ecosystems and returns their discrete scanners
func EcosystemsToScanners(ctx context.Context, ecosystems []*Ecosystem) ([]PackageScanner, []DistributionScanner, []RepositoryScanner, error) {
func EcosystemsToScanners(ctx context.Context, ecosystems []*Ecosystem, disallowRemote bool) ([]PackageScanner, []DistributionScanner, []RepositoryScanner, error) {
log := zerolog.Ctx(ctx).With().
Str("component", "internal/indexer/EcosystemsToScanners").
Logger()
ctx = log.WithContext(ctx)
ps := []PackageScanner{}
ds := []DistributionScanner{}
rs := []RepositoryScanner{}
Expand All @@ -29,32 +37,56 @@ func EcosystemsToScanners(ctx context.Context, ecosystems []*Ecosystem) ([]Packa
return nil, nil, nil, err
}
for _, s := range pscanners {
if _, ok := seen[s.Name()]; !ok {
ps = append(ps, s)
seen[s.Name()] = struct{}{}
n := s.Name()
if _, ok := seen[n]; ok {
continue
}
seen[n] = struct{}{}
if _, ok := s.(RPCScanner); ok && disallowRemote {
log.Info().
Str("scanner", n).
Msg("disallowed by configuration")
continue
}
ps = append(ps, s)
}

dscanners, err := ecosystem.DistributionScanners(ctx)
if err != nil {
return nil, nil, nil, err
}
for _, s := range dscanners {
if _, ok := seen[s.Name()]; !ok {
ds = append(ds, s)
seen[s.Name()] = struct{}{}
n := s.Name()
if _, ok := seen[n]; ok {
continue
}
seen[n] = struct{}{}
if _, ok := s.(RPCScanner); ok && disallowRemote {
log.Info().
Str("scanner", n).
Msg("disallowed by configuration")
continue
}
ds = append(ds, s)
}

rscanners, err := ecosystem.RepositoryScanners(ctx)
if err != nil {
return nil, nil, nil, err
}
for _, s := range rscanners {
if _, ok := seen[s.Name()]; !ok {
rs = append(rs, s)
seen[s.Name()] = struct{}{}
n := s.Name()
if _, ok := seen[n]; ok {
continue
}
seen[n] = struct{}{}
if _, ok := s.(RPCScanner); ok && disallowRemote {
log.Info().
Str("scanner", n).
Msg("disallowed by configuration")
continue
}
rs = append(rs, s)
}
}
return ps, ds, rs, nil
Expand Down
Loading

0 comments on commit a0c9aaa

Please sign in to comment.