diff --git a/providers-sdk/v1/plugin/connection.go b/providers-sdk/v1/plugin/connection.go index 74c9363669..1d329590c2 100644 --- a/providers-sdk/v1/plugin/connection.go +++ b/providers-sdk/v1/plugin/connection.go @@ -8,14 +8,14 @@ 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 a value, + // 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 + ParentID() uint32 } type connection struct { id uint32 - parentId *uint32 + parentId uint32 } func NewConnection(id uint32, asset *inventory.Asset) Connection { @@ -23,7 +23,7 @@ func NewConnection(id uint32, asset *inventory.Asset) Connection { id: id, } if len(asset.Connections) > 0 && asset.Connections[0].ParentConnectionId > 0 { - conn.parentId = &asset.Connections[0].ParentConnectionId + conn.parentId = asset.Connections[0].ParentConnectionId } return conn } @@ -32,6 +32,6 @@ func (c *connection) ID() uint32 { return c.id } -func (c *connection) ParentID() *uint32 { +func (c *connection) ParentID() uint32 { return c.parentId } diff --git a/providers-sdk/v1/plugin/connection_test.go b/providers-sdk/v1/plugin/connection_test.go index a18447c2d2..42198f8d52 100644 --- a/providers-sdk/v1/plugin/connection_test.go +++ b/providers-sdk/v1/plugin/connection_test.go @@ -20,7 +20,7 @@ func TestConnection_ID(t *testing.T) { func TestConnection_ParentID_Nil(t *testing.T) { c := NewConnection(1, &inventory.Asset{}) require.NotNil(t, c) - assert.Nil(t, c.ParentID()) + assert.Equal(t, 0, c.ParentID()) } func TestConnection_ParentID(t *testing.T) { @@ -32,7 +32,7 @@ func TestConnection_ParentID(t *testing.T) { }, }) require.NotNil(t, c) - assert.Equal(t, uint32(2), *c.ParentID()) + assert.Equal(t, uint32(2), c.ParentID()) } func TestConnection_ParentID_0(t *testing.T) { diff --git a/providers-sdk/v1/plugin/service.go b/providers-sdk/v1/plugin/service.go index 2952c0aab7..e983b3f135 100644 --- a/providers-sdk/v1/plugin/service.go +++ b/providers-sdk/v1/plugin/service.go @@ -44,10 +44,10 @@ func (s *Service) AddRuntime(createRuntime func(connId uint32) (*Runtime, error) } if runtime.Connection != nil { - if parentId := runtime.Connection.ParentID(); parentId != nil { - parentRuntime, err := s.doGetRuntime(*parentId) + if parentId := runtime.Connection.ParentID(); parentId > 0 { + parentRuntime, err := s.doGetRuntime(parentId) if err != nil { - return nil, errors.New("parent connection " + strconv.FormatUint(uint64(*parentId), 10) + " not found") + return nil, errors.New("parent connection " + strconv.FormatUint(uint64(parentId), 10) + " not found") } runtime.Resources = parentRuntime.Resources diff --git a/providers-sdk/v1/plugin/service_test.go b/providers-sdk/v1/plugin/service_test.go index 88a5795653..12a06a4cae 100644 --- a/providers-sdk/v1/plugin/service_test.go +++ b/providers-sdk/v1/plugin/service_test.go @@ -14,7 +14,7 @@ import ( type TestConnection struct { id uint32 - parentId *uint32 + parentId uint32 } func newTestConnection(id uint32) *TestConnection { @@ -25,7 +25,7 @@ func (c *TestConnection) ID() uint32 { return c.id } -func (c *TestConnection) ParentID() *uint32 { +func (c *TestConnection) ParentID() uint32 { return c.parentId } @@ -84,7 +84,7 @@ func TestAddRuntime_ParentNotExist(t *testing.T) { parentId := uint32(10) _, err := s.AddRuntime(func(connId uint32) (*Runtime, error) { c := newTestConnection(connId) - c.parentId = &parentId + c.parentId = parentId return &Runtime{ Connection: c, }, nil @@ -110,7 +110,7 @@ func TestAddRuntime_Parent(t *testing.T) { parentId := parent.Connection.ID() child, err := s.AddRuntime(func(connId uint32) (*Runtime, error) { c := newTestConnection(connId) - c.parentId = &parentId + c.parentId = parentId return &Runtime{ Connection: c, }, nil