Skip to content

Commit

Permalink
✨ add aws mock connection (#2076)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
arlimus authored Oct 4, 2023
1 parent 5d810ef commit ccbf91c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
7 changes: 7 additions & 0 deletions providers/aws/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 31 additions & 1 deletion providers/aws/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ccbf91c

Please sign in to comment.