-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⭐️ support re-using MQL cache between provider connections (#3274)
* ⭐️ support re-using MQL cache between provider connections Signed-off-by: Ivan Milchev <[email protected]> * remove go-memoize from k8s provider Signed-off-by: Ivan Milchev <[email protected]> * make k8s discovery reuses mql cache Signed-off-by: Ivan Milchev <[email protected]> * migrate arista provider Signed-off-by: Ivan Milchev <[email protected]> * migrate atlassian provider Signed-off-by: Ivan Milchev <[email protected]> * migrate aws provider Signed-off-by: Ivan Milchev <[email protected]> * migrate os provider Signed-off-by: Ivan Milchev <[email protected]> * migrate azure provider Signed-off-by: Ivan Milchev <[email protected]> * migrate equinix provider Signed-off-by: Ivan Milchev <[email protected]> * re-use plugin.Connection instead of copying functions Signed-off-by: Ivan Milchev <[email protected]> * migrate gcp provider Signed-off-by: Ivan Milchev <[email protected]> * migrate github provider Signed-off-by: Ivan Milchev <[email protected]> * migrate gitlab provider Signed-off-by: Ivan Milchev <[email protected]> * make sure cache is reused for discovered gcp assets Signed-off-by: Ivan Milchev <[email protected]> * migrate google-workspace provider Signed-off-by: Ivan Milchev <[email protected]> * migrate ipmi provider Signed-off-by: Ivan Milchev <[email protected]> * migrate ms365 provider Signed-off-by: Ivan Milchev <[email protected]> * migrate network provider Signed-off-by: Ivan Milchev <[email protected]> * define plugin.Connection and reuse in all providers Signed-off-by: Ivan Milchev <[email protected]> * migrate okta provider Signed-off-by: Ivan Milchev <[email protected]> * migrate opcua provider Signed-off-by: Ivan Milchev <[email protected]> * migrate slack provider Signed-off-by: Ivan Milchev <[email protected]> * migrate terraform provider Signed-off-by: Ivan Milchev <[email protected]> * migrate vcd provider Signed-off-by: Ivan Milchev <[email protected]> * migrate vsphere provider Signed-off-by: Ivan Milchev <[email protected]> * fix test build Signed-off-by: Ivan Milchev <[email protected]> * fix linter error Signed-off-by: Ivan Milchev <[email protected]> * fix mock provider Signed-off-by: Ivan Milchev <[email protected]> * fix dns tests for network provider Signed-off-by: Ivan Milchev <[email protected]> * fix more tests Signed-off-by: Ivan Milchev <[email protected]> * re-use plugin.Connection in os provider Signed-off-by: Ivan Milchev <[email protected]> * fix tests Signed-off-by: Ivan Milchev <[email protected]> * add tests for connection sharing Signed-off-by: Ivan Milchev <[email protected]> * do not use pointer for ParentID Signed-off-by: Ivan Milchev <[email protected]> * use plugin.Connection in winrm Signed-off-by: Ivan Milchev <[email protected]> * fix tests Signed-off-by: Ivan Milchev <[email protected]> --------- Signed-off-by: Ivan Milchev <[email protected]>
- Loading branch information
Showing
125 changed files
with
1,046 additions
and
962 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,37 @@ | ||
// Copyright (c) Mondoo, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package plugin | ||
|
||
import inventory "go.mondoo.com/cnquery/v10/providers-sdk/v1/inventory" | ||
|
||
type Connection interface { | ||
ID() uint32 | ||
|
||
// ParentID returns the ID of the parent connection. If this returns >0, | ||
// the connection with that ID will be used to store and get data. | ||
ParentID() uint32 | ||
} | ||
|
||
type connection struct { | ||
id uint32 | ||
parentId uint32 | ||
} | ||
|
||
func NewConnection(id uint32, asset *inventory.Asset) Connection { | ||
conn := &connection{ | ||
id: id, | ||
} | ||
if len(asset.Connections) > 0 && asset.Connections[0].ParentConnectionId > 0 { | ||
conn.parentId = asset.Connections[0].ParentConnectionId | ||
} | ||
return conn | ||
} | ||
|
||
func (c *connection) ID() uint32 { | ||
return c.id | ||
} | ||
|
||
func (c *connection) ParentID() uint32 { | ||
return c.parentId | ||
} |
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,48 @@ | ||
// Copyright (c) Mondoo, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package plugin | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
inventory "go.mondoo.com/cnquery/v10/providers-sdk/v1/inventory" | ||
) | ||
|
||
func TestConnection_ID(t *testing.T) { | ||
c := NewConnection(1, &inventory.Asset{}) | ||
require.NotNil(t, c) | ||
assert.Equal(t, uint32(1), c.ID()) | ||
} | ||
|
||
func TestConnection_ParentID_Nil(t *testing.T) { | ||
c := NewConnection(1, &inventory.Asset{}) | ||
require.NotNil(t, c) | ||
assert.Equal(t, uint32(0), c.ParentID()) | ||
} | ||
|
||
func TestConnection_ParentID(t *testing.T) { | ||
c := NewConnection(1, &inventory.Asset{ | ||
Connections: []*inventory.Config{ | ||
{ | ||
ParentConnectionId: 2, | ||
}, | ||
}, | ||
}) | ||
require.NotNil(t, c) | ||
assert.Equal(t, uint32(2), c.ParentID()) | ||
} | ||
|
||
func TestConnection_ParentID_0(t *testing.T) { | ||
c := NewConnection(1, &inventory.Asset{ | ||
Connections: []*inventory.Config{ | ||
{ | ||
ParentConnectionId: 0, | ||
}, | ||
}, | ||
}) | ||
require.NotNil(t, c) | ||
assert.Equal(t, uint32(0), c.ParentID()) | ||
} |
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
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
Oops, something went wrong.