From ccbf91c4f7f7f17e32f0c877918624f8f15b393a Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Wed, 4 Oct 2023 01:22:15 -0700 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20add=20aws=20mock=20connection=20(#2?= =?UTF-8?q?076)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follows the pattern of the slack mock connection. Similar to slack, this pattern is not fully streamlined yet. I'll add that in a follow-up shortly, for now this works great :) Signed-off-by: Dominik Richter --- providers/aws/connection/connection.go | 7 ++++++ providers/aws/provider/provider.go | 32 +++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/providers/aws/connection/connection.go b/providers/aws/connection/connection.go index a53f4f15e3..88ecafed95 100644 --- a/providers/aws/connection/connection.go +++ b/providers/aws/connection/connection.go @@ -31,6 +31,13 @@ type AwsConnection struct { connectionOptions map[string]string } +func NewMockConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) *AwsConnection { + return &AwsConnection{ + id: id, + asset: asset, + } +} + func NewAwsConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*AwsConnection, error) { log.Debug().Msg("new aws connection") // check flags for connection options diff --git a/providers/aws/provider/provider.go b/providers/aws/provider/provider.go index 5c6c2b76da..0c6e7dcb32 100644 --- a/providers/aws/provider/provider.go +++ b/providers/aws/provider/provider.go @@ -108,7 +108,33 @@ func (s *Service) Shutdown(req *plugin.ShutdownReq) (*plugin.ShutdownRes, error) } func (s *Service) MockConnect(req *plugin.ConnectReq, callback plugin.ProviderCallback) (*plugin.ConnectRes, error) { - return nil, errors.New("mock connect not yet implemented") + if req == nil || req.Asset == nil { + return nil, errors.New("no connection data provided") + } + + asset := &inventory.Asset{ + PlatformIds: req.Asset.PlatformIds, + Platform: req.Asset.Platform, + Connections: []*inventory.Config{{ + Type: "mock", + }}, + } + + conn, err := s.connect(&plugin.ConnectReq{ + Features: req.Features, + Upstream: req.Upstream, + Asset: asset, + }, callback) + if err != nil { + return nil, err + } + + return &plugin.ConnectRes{ + Id: uint32(conn.(shared.Connection).ID()), + Name: conn.(shared.Connection).Name(), + Asset: asset, + Inventory: nil, + }, nil } func (s *Service) Connect(req *plugin.ConnectReq, callback plugin.ProviderCallback) (*plugin.ConnectRes, error) { @@ -161,6 +187,10 @@ func (s *Service) connect(req *plugin.ConnectReq, callback plugin.ProviderCallba var err error switch conf.Type { + case "mock": + s.lastConnectionID++ + conn = connection.NewMockConnection(s.lastConnectionID, asset, conf) + case string(awsec2ebsconn.EBSConnectionType): s.lastConnectionID++ conn, err = awsec2ebsconn.NewAwsEbsConnection(s.lastConnectionID, conf, asset)