-
Notifications
You must be signed in to change notification settings - Fork 174
ROX-12943: Sensor sets NodeID in NodeInventory #4484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
90185b2
Provide imageScanServiceClient to clairify
vikin91 47418eb
Implement Sensor part from ROX-12943
vikin91 2c640ca
Make log messages more informative
vikin91 996abd1
Remove clairify part that should belong to another PR
vikin91 67df967
Fix style by adding comments to exported methods
vikin91 d07ac33
Simplify handling nodeInventory in nodeInventoryHandlerImpl
vikin91 b025225
Add test coverage for nodeInventoryHandlerImpl.findNodeID
vikin91 0370da4
Do not generate mocks for store.NodeStore
vikin91 ef0bcc0
Resolve conflicts between mocks
vikin91 cb9b884
Fix style issues
vikin91 dd86595
Readd accidentally deleted OnDeploymentCreateOrUpdateByID
vikin91 e35935e
Cleanup nodeDispatcher.ProcessEvent
vikin91 37a8473
Remove redundant parameter NodeStore
vikin91 84c3758
Refactor nodeStore interface
vikin91 f286fd1
Simplify NodeIdMatcher
vikin91 bc1c0a2
Rerun code generation
vikin91 fa71e38
Refactor nodeStore interfaces
vikin91 f4d7882
Fix comments
vikin91 48c2883
Add testcase for NodeInventoryHandler with nil input
vikin91 91c1ac1
Add testcase for NodeInventoryHandler when no node can be found
vikin91 64842db
Fix comment
vikin91 ddf0af3
Remove duplicate interface
vikin91 727b9b2
Make InMemoryStoreProvider.Nodes() return store.NodeStore
vikin91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,32 @@ | ||
| package compliance | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/stackrox/rox/sensor/common/store" | ||
| ) | ||
|
|
||
| // NodeIDMatcher helps finding NodeWrap by name | ||
| type NodeIDMatcher interface { | ||
| GetNodeID(nodename string) (string, error) | ||
| } | ||
|
|
||
| // NodeIDMatcherImpl finds Node by name within NodeStore | ||
| type NodeIDMatcherImpl struct { | ||
| nodeStore store.NodeStore | ||
| } | ||
|
|
||
| // NewNodeIDMatcher creates a NodeIDMatcherImpl | ||
| func NewNodeIDMatcher(store store.NodeStore) *NodeIDMatcherImpl { | ||
| return &NodeIDMatcherImpl{ | ||
| nodeStore: store, | ||
| } | ||
| } | ||
|
|
||
| // GetNodeID returns NodeID if a Node with matching name has been found | ||
| func (c *NodeIDMatcherImpl) GetNodeID(nodename string) (string, error) { | ||
| if node := c.nodeStore.GetNode(nodename); node != nil { | ||
| return node.GetId(), nil | ||
| } | ||
| return "", fmt.Errorf("cannot find node with name '%s'", nodename) | ||
| } |
This file contains hidden or 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,81 @@ | ||
| package compliance | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/pkg/errors" | ||
| "github.com/stackrox/rox/generated/storage" | ||
| "github.com/stretchr/testify/suite" | ||
| ) | ||
|
|
||
| func TestNodeIDMatcher(t *testing.T) { | ||
| suite.Run(t, &NodeInventoryHandlerImplTestSuite{}) | ||
| } | ||
|
|
||
| var _ suite.TearDownTestSuite = (*NodeInventoryHandlerTestSuite)(nil) | ||
|
|
||
| type NodeInventoryHandlerImplTestSuite struct { | ||
| suite.Suite | ||
| } | ||
|
|
||
| func (s *NodeInventoryHandlerImplTestSuite) TestNodeIDMatcherGetNodeID() { | ||
| dummy := make(chan *storage.NodeInventory) | ||
| defer close(dummy) | ||
|
|
||
| tt := map[string]struct { | ||
| storageState map[string]string | ||
| namesToExpectedIDs map[string]string | ||
| }{ | ||
| "Existing node is found": { | ||
| storageState: map[string]string{ | ||
| "node1": "id1", | ||
| }, | ||
| namesToExpectedIDs: map[string]string{ | ||
| "node1": "id1", | ||
| "node2": "", | ||
| }, | ||
| }, | ||
| "Empty store": { | ||
| storageState: map[string]string{}, | ||
| namesToExpectedIDs: map[string]string{ | ||
| "node1": "", | ||
| "node2": "", | ||
| }, | ||
| }, | ||
| } | ||
| for name, tc := range tt { | ||
| s.Run(name, func() { | ||
| matcher := newMockNodeIDMatcher(tc.storageState) | ||
| for nodeName, expectedID := range tc.namesToExpectedIDs { | ||
| gotID, gotErr := matcher.GetNodeID(nodeName) | ||
| s.Equal(expectedID, gotID, "ID mismatch for inventory '%s'", nodeName) | ||
| if gotID != "" { | ||
| s.Nil(gotErr) | ||
| } else { | ||
| s.NotNil(gotErr) | ||
| } | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| // mockNodeIDMatcher always finds a node when GetNodeResource is called | ||
| type mockNodeIDMatcher struct { | ||
| nodeStore map[string]string | ||
| } | ||
|
|
||
| // newMockNodeIDMatcher builds mockNodeIDMatcher | ||
| func newMockNodeIDMatcher(store map[string]string) *mockNodeIDMatcher { | ||
| return &mockNodeIDMatcher{ | ||
| nodeStore: store, | ||
| } | ||
| } | ||
|
|
||
| // GetNodeID searches for nodeID in the map and returns it when found | ||
| func (c *mockNodeIDMatcher) GetNodeID(nodename string) (string, error) { | ||
| if val, ok := c.nodeStore[nodename]; ok { | ||
| return val, nil | ||
| } | ||
| return "", errors.New("node not found") | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.