From 4b811ac311f37d2e40bd77cd3292c04ec7354a66 Mon Sep 17 00:00:00 2001 From: Gert Drapers <1533850+gertd@users.noreply.github.com> Date: Mon, 15 Jul 2024 13:15:40 -0700 Subject: [PATCH] cleanup NewCommonCtx --- pkg/cc/ccc.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pkg/cc/ccc.go b/pkg/cc/ccc.go index 9947a6b..f4f6146 100644 --- a/pkg/cc/ccc.go +++ b/pkg/cc/ccc.go @@ -7,30 +7,34 @@ 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, @@ -38,8 +42,9 @@ func NewCommonCtx(configPath config.Path, overrides ...config.Overrider) (*Commo Environment: services, Auth: settings, CachedToken: cachedToken, - DecisionLogger: decisionloggerSettings, + DecisionLogger: dlSettings, } + return commonCtx, nil }