Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion providers/okta/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ package connection
import (
"context"
"errors"

"github.com/okta/okta-sdk-golang/v2/okta"
"github.com/rs/zerolog/log"
"go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory"
"go.mondoo.com/cnquery/v9/providers-sdk/v1/vault"
)

func NewMockConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) *OktaConnection {
return &OktaConnection{
id: id,
asset: asset,
}
}

type OktaConnection struct {
id uint32
Conf *inventory.Config
Expand Down
31 changes: 30 additions & 1 deletion providers/okta/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,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.ID()),
Name: conn.Name(),
Asset: asset,
Inventory: nil,
}, nil
}

func (s *Service) Connect(req *plugin.ConnectReq, callback plugin.ProviderCallback) (*plugin.ConnectRes, error) {
Expand Down Expand Up @@ -131,6 +157,9 @@ 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)
default:
s.lastConnectionID++
conn, err = connection.NewOktaConnection(s.lastConnectionID, asset, conf)
Expand Down