Skip to content

Commit

Permalink
cleanup NewCommonCtx
Browse files Browse the repository at this point in the history
  • Loading branch information
gertd committed Jul 15, 2024
1 parent 89cbee7 commit 4b811ac
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions pkg/cc/ccc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,44 @@ import (
"github.com/aserto-dev/aserto/pkg/cc/clients"
"github.com/aserto-dev/aserto/pkg/cc/config"
"github.com/aserto-dev/aserto/pkg/cc/token"
decisionlogger "github.com/aserto-dev/aserto/pkg/decision_logger"
dl "github.com/aserto-dev/aserto/pkg/decision_logger"
)

// CommonContext Constructor extraction from wire

// NewCommonCtx, CommonContext constructor (extracted from wire).
func NewCommonCtx(configPath config.Path, overrides ...config.Overrider) (*CommonCtx, error) {
contextContext := context.Background()
configConfig, err := config.NewConfig(configPath, overrides...)
if err != nil {
return nil, err
}

services := &configConfig.Services
auth := configConfig.Auth

cacheKey := GetCacheKey(auth)
cachedToken := token.Load(cacheKey)

tenantID := NewTenantID(configConfig, cachedToken)
asertoFactory, err := clients.NewClientFactory(contextContext, services, tenantID, cachedToken)
if err != nil {
return nil, err
}

settings := NewAuthSettings(auth)
decisionloggerConfig := &configConfig.DecisionLogger
decisionloggerSettings := decisionlogger.NewSettings(decisionloggerConfig)
// stdIO := iostream.DefaultIO()

dlConfig := &configConfig.DecisionLogger
dlSettings := dl.NewSettings(dlConfig)

commonCtx := &CommonCtx{
Factory: asertoFactory,
Context: contextContext,
Config: configConfig,
Environment: services,
Auth: settings,
CachedToken: cachedToken,
DecisionLogger: decisionloggerSettings,
DecisionLogger: dlSettings,
}

return commonCtx, nil
}

Expand Down

0 comments on commit 4b811ac

Please sign in to comment.