Skip to content

Commit

Permalink
🧹 cleanup scanner logic
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev committed Feb 16, 2024
1 parent 95d52fc commit b06be8e
Showing 1 changed file with 0 additions and 23 deletions.
23 changes: 0 additions & 23 deletions policy/scan/local_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ type LocalScanner struct {
allowJobCredentials bool
disableProgressBar bool
reportType ReportType
scanMutex sync.Mutex
}

type ScannerOption func(*LocalScanner)
Expand Down Expand Up @@ -136,13 +135,6 @@ func (s *LocalScanner) Schedule(ctx context.Context, job *Job) (*Empty, error) {
}

func (s *LocalScanner) Run(ctx context.Context, job *Job) (*ScanResult, error) {
// We want to run 1 scan at a time because we kill all providers after a scan.
// If we do >1 scan in parallel it is possible that we kill the provider of the
// scan that is in progress, which will result in errors. We can address this later
// by attaching a provider to a scan and killing only the providers that are not
// not actively used.
s.scanMutex.Lock()
defer s.scanMutex.Unlock()
if job == nil {
return nil, status.Errorf(codes.InvalidArgument, "missing scan job")
}
Expand Down Expand Up @@ -273,9 +265,6 @@ func createReporter(ctx context.Context, job *Job, upstream *upstream.UpstreamCo
}

func (s *LocalScanner) distributeJob(job *Job, ctx context.Context, upstream *upstream.UpstreamConfig) (*ScanResult, error) {
// Always shut down the coordinator, to make sure providers are killed
defer providers.Coordinator.Shutdown()

reporter, err := createReporter(ctx, job, upstream)
if err != nil {
return nil, err
Expand Down Expand Up @@ -434,18 +423,6 @@ func (s *LocalScanner) distributeJob(job *Job, ctx context.Context, upstream *up
return reporter.Reports(), nil
}

func batch[T any](list []T, batchSize int) [][]T {
var res [][]T
for i := 0; i < len(list); i += batchSize {
end := i + batchSize
if end > len(list) {
end = len(list)
}
res = append(res, list[i:end])
}
return res
}

func (s *LocalScanner) upstreamServices(conf *upstream.UpstreamConfig) *policy.Services {
if conf == nil ||
conf.ApiEndpoint == "" ||
Expand Down

0 comments on commit b06be8e

Please sign in to comment.