forked from quay/claircore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* bug fixes this commit preliminarily fixes several bugs. it is not an error to reach layer fetch state and have no layers to fetch. pretty_name value on a vuln object was in the wrong order when scanned from the database ubuntu 16.04 has the wrong value in it's release struct * add python repo scanner in order to support index assisted manifest content lookup a repository record must exist in the db to index. this commit adds a repository scanner which indexes a repository when any pip repository is found in a layer. * data model update this commit adds the manifest_index table to the indexer data model. this table allows the contents of a manifest to be searched via an index. * omnimatcher package this commit adds a package which uses all known matchers to understand if a particular IndexRecord is vulnerable to a particular manifest. * persistence this commit adds methods to the indexer's store interface for persiting to and retreiving from the manifest index. a refactor of the store into better grouped interfaces is performed as well. * indexer plumbing in this commit a new state is added to the Indexer's state machine dubbed IndexManifest. In this state a coalesced index report is persisted to the manifest_index table. Refactoring all the state definitinos to their own file is performed as well. Signed-off-by: ldelossa <ldelossa@redhat.com> * tests this commit adds tests to both the indexer state machine and the new affected manifest persistence methods Signed-off-by: ldelossa <ldelossa@redhat.com> * pr fixes and various fixes this commit handles some PR review fixes, finds and fixes an absence of error handling in registerscanners method and adds a max group size for concurrent handling of affected manifests requests * further pr fixes
- Loading branch information
Louis DeLosSantos
authored
May 29, 2020
1 parent
c7de532
commit c4a279b
Showing
48 changed files
with
1,388 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package controller | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/quay/claircore/internal/indexer" | ||
) | ||
|
||
// Test_Coalesce confirms when no error is encountered | ||
// the the coalesce method will transition to the correct | ||
// state | ||
// | ||
// this test simply provides no Ecosystems to the index | ||
// controller and does no work. | ||
func Test_Coalesce(t *testing.T) { | ||
ctx, done := context.WithCancel(context.Background()) | ||
defer done() | ||
var tt = []struct { | ||
name string | ||
expectedState State | ||
}{ | ||
{ | ||
name: "successful index", | ||
expectedState: IndexManifest, | ||
}, | ||
} | ||
|
||
for _, table := range tt { | ||
t.Run(table.name, func(t *testing.T) { | ||
ctx, done := context.WithCancel(ctx) | ||
defer done() | ||
indexer := New(&indexer.Opts{}) | ||
|
||
state, err := coalesce(ctx, indexer) | ||
if err != nil { | ||
t.Fatalf("did not expect error: %v", err) | ||
} | ||
if table.expectedState != state { | ||
t.Fatalf("got: %s, wanted: %s", table.expectedState, state) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package controller | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/rs/zerolog" | ||
) | ||
|
||
func indexManifest(ctx context.Context, c *Controller) (State, error) { | ||
log := zerolog.Ctx(ctx).With(). | ||
Str("state", c.getState().String()). | ||
Logger() | ||
ctx = log.WithContext(ctx) | ||
log.Info().Msg("starting to index manifest...") | ||
|
||
if c.report == nil { | ||
return Terminal, fmt.Errorf("reached IndexManifest state with a nil report field. cannot continue") | ||
} | ||
|
||
err := c.Store.IndexManifest(ctx, c.report) | ||
if err != nil { | ||
return Terminal, fmt.Errorf("indexing manifest contents failed: %v", err) | ||
} | ||
return IndexFinished, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package controller | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
"github.com/quay/claircore/internal/indexer" | ||
) | ||
|
||
func Test_IndexManifest(t *testing.T) { | ||
ctx, done := context.WithCancel(context.Background()) | ||
defer done() | ||
var tt = []struct { | ||
name string | ||
expectedState State | ||
mock func(t *testing.T) indexer.Store | ||
}{ | ||
{ | ||
name: "successful index", | ||
expectedState: IndexFinished, | ||
mock: func(t *testing.T) indexer.Store { | ||
ctrl := gomock.NewController(t) | ||
s := indexer.NewMockStore(ctrl) | ||
s.EXPECT().IndexManifest(gomock.Any(), gomock.Any()).Return(nil) | ||
return s | ||
}, | ||
}, | ||
} | ||
|
||
for _, table := range tt { | ||
t.Run(table.name, func(t *testing.T) { | ||
ctx, done := context.WithCancel(ctx) | ||
defer done() | ||
s := table.mock(t) | ||
indexer := New(&indexer.Opts{ | ||
Store: s, | ||
}) | ||
|
||
state, err := indexManifest(ctx, indexer) | ||
if err != nil { | ||
t.Fatalf("did not expect error: %v", err) | ||
} | ||
if table.expectedState != state { | ||
t.Fatalf("got: %v, want: %v", state, table.expectedState) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_IndexManifest_Failure(t *testing.T) { | ||
ctx, done := context.WithCancel(context.Background()) | ||
defer done() | ||
var tt = []struct { | ||
name string | ||
expectedState State | ||
mock func(t *testing.T) indexer.Store | ||
}{ | ||
{ | ||
name: "index failure", | ||
expectedState: Terminal, | ||
mock: func(t *testing.T) indexer.Store { | ||
ctrl := gomock.NewController(t) | ||
s := indexer.NewMockStore(ctrl) | ||
s.EXPECT().IndexManifest(gomock.Any(), gomock.Any()).Return(fmt.Errorf("failure")) | ||
return s | ||
}, | ||
}, | ||
} | ||
|
||
for _, table := range tt { | ||
t.Run(table.name, func(t *testing.T) { | ||
ctx, done := context.WithCancel(ctx) | ||
defer done() | ||
s := table.mock(t) | ||
indexer := New(&indexer.Opts{ | ||
Store: s, | ||
}) | ||
|
||
state, err := indexManifest(ctx, indexer) | ||
if err == nil { | ||
t.Fatalf("expected error") | ||
} | ||
if table.expectedState != state { | ||
t.Fatalf("got: %v, want: %v", state, table.expectedState) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.