Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions libvuln/driver/updaterset.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package driver

import (
"context"
"errors"
"fmt"
"net/http"
"regexp"
"strings"
)

// ErrExists is an error returned if the updater
Expand Down Expand Up @@ -104,3 +107,31 @@ func (s *UpdaterSet) RegexFilter(regex string) error {
}
return nil
}

// Configure calls the Configure method on all the passed-in
// UpdaterSetFactories.
func Configure(ctx context.Context, fs map[string]UpdaterSetFactory, cfg map[string]ConfigUnmarshaler, c *http.Client) error {
errd := false
var b strings.Builder
b.WriteString("updater: errors configuring factories:")
if c == nil {
c = http.DefaultClient
}

for name, fac := range fs {
f, fOK := fac.(Configurable)
cf, cfOK := cfg[name]
if fOK && cfOK {
if err := f.Configure(ctx, cf, c); err != nil {
errd = true
b.WriteString("\n\t")
b.WriteString(err.Error())
}
}
}

if errd {
return errors.New(b.String())
}
return nil
}
2 changes: 1 addition & 1 deletion libvuln/updates/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func NewManager(ctx context.Context, store vulnstore.Updater, pool *pgxpool.Pool
return nil, errors.New("update retention cannot be 1")
}

err := updater.Configure(ctx, m.factories, m.configs, m.client)
err := driver.Configure(ctx, m.factories, m.configs, m.client)
if err != nil {
return nil, fmt.Errorf("failed to configure updater set factory: %w", err)
}
Expand Down
32 changes: 0 additions & 32 deletions updater/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
package updater

import (
"context"
"errors"
"net/http"
"strings"
"sync"

"github.com/quay/claircore/libvuln/driver"
Expand Down Expand Up @@ -43,31 +39,3 @@ func Registered() map[string]driver.UpdaterSetFactory {
}
return r
}

// Configure calls the Configure method on all the passed-in
// UpdaterSetFactories.
func Configure(ctx context.Context, fs map[string]driver.UpdaterSetFactory, cfg map[string]driver.ConfigUnmarshaler, c *http.Client) error {
errd := false
var b strings.Builder
b.WriteString("updater: errors configuring factories:")
if c == nil {
c = http.DefaultClient
}

for name, fac := range fs {
f, fOK := fac.(driver.Configurable)
cf, cfOK := cfg[name]
if fOK && cfOK {
if err := f.Configure(ctx, cf, c); err != nil {
errd = true
b.WriteString("\n\t")
b.WriteString(err.Error())
}
}
}

if errd {
return errors.New(b.String())
}
return nil
}