Skip to content

Commit

Permalink
services: update initialization
Browse files Browse the repository at this point in the history
Claircore refactoring necessitates Clair to be more verbose in its
service instanciation, all the dependecies are now created explicitly
in the initialization step and passed to the constructors via the
respective Options structs.

Signed-off-by: crozzy <joseph.crosland@gmail.com>
Signed-off-by: Hank Donnay <hdonnay@redhat.com>
  • Loading branch information
crozzy committed Jul 18, 2022
1 parent 6a6fd90 commit 668f443
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 24 deletions.
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ require (
github.com/go-stomp/stomp v2.0.8+incompatible
github.com/google/go-cmp v0.5.7
github.com/google/go-containerregistry v0.6.1
github.com/google/uuid v1.2.0
github.com/google/uuid v1.3.0
github.com/jackc/pgconn v1.10.1
github.com/jackc/pgx/v4 v4.13.0
github.com/klauspost/compress v1.13.6
github.com/ldelossa/responserecorder v1.0.2-0.20210711162258-40bec93a9325
github.com/prometheus/client_golang v1.12.2
github.com/quay/clair/config v1.0.0
github.com/quay/claircore v1.4.4
github.com/quay/clair/config v1.1.3
github.com/quay/claircore v1.4.5-0.20220718031238-8f0d7d98bd27
github.com/quay/zlog v1.1.3
github.com/remind101/migrate v0.0.0-20170729031349-52c1edff7319
github.com/rs/zerolog v1.26.1
Expand Down Expand Up @@ -70,6 +70,8 @@ require (
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/quay/alas v1.0.1 // indirect
github.com/quay/claircore/toolkit v1.0.0 // indirect
github.com/quay/claircore/updater/driver v1.0.0 // indirect
github.com/quay/goval-parser v0.8.6 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
Expand All @@ -82,7 +84,5 @@ require (
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.10 // indirect
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect
google.golang.org/protobuf v1.26.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
)

replace github.com/quay/clair/config => ./config
20 changes: 12 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,9 @@ github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm4
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs=
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
Expand Down Expand Up @@ -833,11 +834,16 @@ github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/quay/alas v1.0.1 h1:MuFpGGXyZlDD7+F/hrnMZmzhS8P2bjRzX9DyGmyLA+0=
github.com/quay/alas v1.0.1/go.mod h1:pseepSrG9pwry1joG7RO/RNRFJaWqiqx9qeoomeYwEk=
github.com/quay/claircore v1.4.4 h1:Wl8Yd5Y0vRfgYJynHlZD8+EKgccpQpjZTHStpvy1Cio=
github.com/quay/claircore v1.4.4/go.mod h1:CxlF+cUo1f52KiCIFVR65SZn1x5q3ElDKZZ1Ygdud+o=
github.com/quay/clair/config v1.1.3 h1:z9wmMQFJASQZwQKSTH3VV1A37dov10mLgutUSRBM4cI=
github.com/quay/clair/config v1.1.3/go.mod h1:3mfaS7n0V/+lHMJ72SBbaiD+fTi/us1j/Ad8fvE6j5U=
github.com/quay/claircore v1.4.5-0.20220718031238-8f0d7d98bd27 h1:8I1JJ/RDhDxd0Gm4is/Rq/C2d8+lROQN/Ja8Kip7RbM=
github.com/quay/claircore v1.4.5-0.20220718031238-8f0d7d98bd27/go.mod h1:hK+FkemJjDk7X5VT+WeR82K8NFcv1FXmKn/JPqg7x5U=
github.com/quay/claircore/toolkit v1.0.0 h1:FiAo/URPMa62D9KN0YhyK+ATObtXl4I8/Jsf69GEHYM=
github.com/quay/claircore/toolkit v1.0.0/go.mod h1:3ELtgf92x7o1JCTSKVOAqhcnCTXc4s5qiGaEDx62i20=
github.com/quay/claircore/updater/driver v1.0.0 h1:w7dAUjO3GBK6RjNyTZ2Kwz0l/Wuic3ykKJWPB80uA94=
github.com/quay/claircore/updater/driver v1.0.0/go.mod h1:My5aY1wBpgxcWaHQZ0VoPmmj/EzuH7fq4ntzJbos4OI=
github.com/quay/goval-parser v0.8.6 h1:h1Xg3SZR/6I7UVa1LcsQZvQft/q7sJbosmFrjzSmdqE=
github.com/quay/goval-parser v0.8.6/go.mod h1:Y0NTNfPYOC7yxsYKzJOrscTWUPq1+QbtHw4XpPXWPMc=
github.com/quay/zlog v1.1.0/go.mod h1:szs9k88lsac48+Wm6QTnpObO67tu0oMr/p5V6qmPEIw=
github.com/quay/zlog v1.1.3 h1:3N9PFFe4ugIyHN+Ed0qOyFTWB61dBeSqg2wEb3g4+ks=
github.com/quay/zlog v1.1.3/go.mod h1:szs9k88lsac48+Wm6QTnpObO67tu0oMr/p5V6qmPEIw=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
Expand Down Expand Up @@ -949,7 +955,6 @@ github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijb
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo=
github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
github.com/vishvananda/netlink v0.0.0-20181108222139-023a6dafdcdf/go.mod h1:+SR5DhBJrl6ZM7CoCKvpw5BKroDKQ+PJqOg65H/2ktk=
Expand Down Expand Up @@ -1148,7 +1153,6 @@ golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLd
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
Expand Down Expand Up @@ -1372,7 +1376,6 @@ golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
golang.org/x/tools v0.1.9/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU=
golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20=
Expand Down Expand Up @@ -1509,8 +1512,9 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
50 changes: 40 additions & 10 deletions initialize/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import (
"fmt"
"net/http"
"net/http/cookiejar"
"os"
"time"

"github.com/jackc/pgx/v4/pgxpool"
"github.com/quay/clair/config"
"github.com/quay/claircore/datastore/postgres"
"github.com/quay/claircore/enricher/cvss"
"github.com/quay/claircore/libindex"
"github.com/quay/claircore/libvuln"
Expand All @@ -27,7 +29,7 @@ import (
"github.com/quay/clair/v4/internal/httputil"
"github.com/quay/clair/v4/matcher"
"github.com/quay/clair/v4/notifier"
"github.com/quay/clair/v4/notifier/postgres"
notifierpg "github.com/quay/clair/v4/notifier/postgres"
"github.com/quay/clair/v4/notifier/service"
)

Expand Down Expand Up @@ -117,11 +119,25 @@ func localIndexer(ctx context.Context, cfg *config.Config) (indexer.Service, err
mkErr := func(err error) *clairerror.ErrNotInitialized {
return &clairerror.ErrNotInitialized{msg + err.Error()}
}
opts := libindex.Opts{
ConnString: cfg.Indexer.ConnString,

pool, err := postgres.Connect(ctx, cfg.Indexer.ConnString, "libindex")
if err != nil {
return nil, mkErr(err)
}
store, err := postgres.InitPostgresIndexerStore(ctx, pool, cfg.Indexer.Migrations)
if err != nil {
return nil, mkErr(err)
}
locker, err := ctxlock.New(ctx, pool)
if err != nil {
return nil, mkErr(err)
}

opts := libindex.Options{
Store: store,
Locker: locker,
ScanLockRetry: time.Duration(cfg.Indexer.ScanLockRetry) * time.Second,
LayerScanConcurrency: cfg.Indexer.LayerScanConcurrency,
Migrations: cfg.Indexer.Migrations,
Airgap: cfg.Indexer.Airgap,
}
if cfg.Indexer.Scanner.Package != nil {
Expand Down Expand Up @@ -172,6 +188,8 @@ func localIndexer(ctx context.Context, cfg *config.Config) (indexer.Service, err
return nil, mkErr(err)
}

opts.FetchArena = libindex.NewRemoteFetchArena(c, os.TempDir())

s, err := libindex.New(ctx, &opts, c)
if err != nil {
return nil, mkErr(err)
Expand Down Expand Up @@ -248,10 +266,22 @@ func localMatcher(ctx context.Context, cfg *config.Config) (matcher.Service, err
return json.Unmarshal(b, v)
}
}
s, err := libvuln.New(ctx, &libvuln.Opts{
MaxConnPool: int32(cfg.Matcher.MaxConnPool),
ConnString: cfg.Matcher.ConnString,
Migrations: cfg.Matcher.Migrations,
pool, err := postgres.Connect(ctx, cfg.Matcher.ConnString, "libvuln")
if err != nil {
return nil, mkErr(err)
}
store, err := postgres.InitPostgresMatcherStore(ctx, pool, cfg.Matcher.Migrations)
if err != nil {
return nil, mkErr(err)
}
locker, err := ctxlock.New(ctx, pool)
if err != nil {
return nil, mkErr(err)
}

s, err := libvuln.New(ctx, &libvuln.Options{
Store: store,
Locker: locker,
UpdaterSets: cfg.Updaters.Sets,
UpdateInterval: cfg.Matcher.Period,
UpdaterConfigs: updaterConfigs,
Expand Down Expand Up @@ -301,15 +331,15 @@ func localNotifier(ctx context.Context, cfg *config.Config, i indexer.Service, m
return nil, mkErr(err)
}
if cfg.Notifier.Migrations {
if err := postgres.Init(ctx, poolcfg.ConnConfig); err != nil {
if err := notifierpg.Init(ctx, poolcfg.ConnConfig); err != nil {
return nil, mkErr(err)
}
}
pool, err := pgxpool.ConnectConfig(ctx, poolcfg)
if err != nil {
return nil, mkErr(err)
}
store := postgres.NewStore(pool)
store := notifierpg.NewStore(pool)
locks, err := ctxlock.New(ctx, pool)
if err != nil {
return nil, mkErr(err)
Expand Down

0 comments on commit 668f443

Please sign in to comment.