Skip to content

Commit 6d98d88

Browse files
committed
updaterset: improve cohesion
Currently the logic which invokes Configurable updaterset lives in registry package. IMO, this doesn't really have any association with registry, it is more close to updaterset. Signed-off-by: Arunprasad Rajkumar [email protected]
1 parent 7856456 commit 6d98d88

File tree

3 files changed

+32
-33
lines changed

3 files changed

+32
-33
lines changed

libvuln/driver/updaterset.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package driver
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
7+
"net/http"
68
"regexp"
9+
"strings"
710
)
811

912
// ErrExists is an error returned if the updater
@@ -104,3 +107,31 @@ func (s *UpdaterSet) RegexFilter(regex string) error {
104107
}
105108
return nil
106109
}
110+
111+
// Configure calls the Configure method on all the passed-in
112+
// UpdaterSetFactories.
113+
func Configure(ctx context.Context, fs map[string]UpdaterSetFactory, cfg map[string]ConfigUnmarshaler, c *http.Client) error {
114+
errd := false
115+
var b strings.Builder
116+
b.WriteString("updater: errors configuring factories:")
117+
if c == nil {
118+
c = http.DefaultClient
119+
}
120+
121+
for name, fac := range fs {
122+
f, fOK := fac.(Configurable)
123+
cf, cfOK := cfg[name]
124+
if fOK && cfOK {
125+
if err := f.Configure(ctx, cf, c); err != nil {
126+
errd = true
127+
b.WriteString("\n\t")
128+
b.WriteString(err.Error())
129+
}
130+
}
131+
}
132+
133+
if errd {
134+
return errors.New(b.String())
135+
}
136+
return nil
137+
}

libvuln/updates/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func NewManager(ctx context.Context, store vulnstore.Updater, pool *pgxpool.Pool
8383
return nil, errors.New("update retention cannot be 1")
8484
}
8585

86-
err := updater.Configure(ctx, m.factories, m.configs, m.client)
86+
err := driver.Configure(ctx, m.factories, m.configs, m.client)
8787
if err != nil {
8888
return nil, fmt.Errorf("failed to configure updater set factory: %w", err)
8989
}

updater/registry.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
package updater
66

77
import (
8-
"context"
9-
"errors"
10-
"net/http"
11-
"strings"
128
"sync"
139

1410
"github.com/quay/claircore/libvuln/driver"
@@ -43,31 +39,3 @@ func Registered() map[string]driver.UpdaterSetFactory {
4339
}
4440
return r
4541
}
46-
47-
// Configure calls the Configure method on all the passed-in
48-
// UpdaterSetFactories.
49-
func Configure(ctx context.Context, fs map[string]driver.UpdaterSetFactory, cfg map[string]driver.ConfigUnmarshaler, c *http.Client) error {
50-
errd := false
51-
var b strings.Builder
52-
b.WriteString("updater: errors configuring factories:")
53-
if c == nil {
54-
c = http.DefaultClient
55-
}
56-
57-
for name, fac := range fs {
58-
f, fOK := fac.(driver.Configurable)
59-
cf, cfOK := cfg[name]
60-
if fOK && cfOK {
61-
if err := f.Configure(ctx, cf, c); err != nil {
62-
errd = true
63-
b.WriteString("\n\t")
64-
b.WriteString(err.Error())
65-
}
66-
}
67-
}
68-
69-
if errd {
70-
return errors.New(b.String())
71-
}
72-
return nil
73-
}

0 commit comments

Comments
 (0)