@@ -5,11 +5,16 @@ import (
55 "fmt"
66
77 "github.com/tetratelabs/wazero"
8+ "google.golang.org/grpc"
89)
910
10- const (
11- ConfidenceDomain = "edge-grpc.spotify.com"
12- )
11+ // ConnFactory is an advanced/testing hook allowing callers to customize how
12+ // gRPC connections are created. The provider will pass the computed target and
13+ // its default DialOptions (TLS and required interceptors where applicable).
14+ // Implementations may modify options, change targets, or replace the dialing
15+ // mechanism entirely. Returning a connection with incompatible security/auth
16+ // can break functionality; use with care.
17+ type ConnFactory func (ctx context.Context , target string , defaultOpts []grpc.DialOption ) (grpc.ClientConnInterface , error )
1318
1419// ProviderConfig holds configuration for the Confidence provider
1520type ProviderConfig struct {
@@ -18,11 +23,8 @@ type ProviderConfig struct {
1823 APIClientSecret string
1924 ClientSecret string
2025
21- // Optional: Custom service addresses (for advanced use cases only)
22- // If not provided, defaults to global region
23- ResolverStateServiceAddr string
24- FlagLoggerServiceAddr string
25- AuthServiceAddr string
26+ // Advanced/testing: override connection creation
27+ ConnFactory ConnFactory
2628}
2729
2830// ProviderConfigWithStateProvider holds configuration for the Confidence provider with a custom StateProvider
@@ -61,40 +63,30 @@ func NewProvider(ctx context.Context, config ProviderConfig) (*LocalResolverProv
6163 return nil , fmt .Errorf ("ClientSecret is required" )
6264 }
6365
64- // Set service addresses to defaults if not provided
65- resolverStateServiceAddr := config .ResolverStateServiceAddr
66- if resolverStateServiceAddr == "" {
67- resolverStateServiceAddr = ConfidenceDomain
68- }
69-
70- flagLoggerServiceAddr := config .FlagLoggerServiceAddr
71- if flagLoggerServiceAddr == "" {
72- flagLoggerServiceAddr = ConfidenceDomain
73- }
74-
75- authServiceAddr := config .AuthServiceAddr
76- if authServiceAddr == "" {
77- authServiceAddr = ConfidenceDomain
78- }
79-
8066 // Use embedded WASM module
8167 wasmBytes := defaultWasmBytes
8268
8369 runtimeConfig := wazero .NewRuntimeConfig ()
8470 wasmRuntime := wazero .NewRuntimeWithConfig (ctx , runtimeConfig )
8571
72+ // Build connection factory (use default if none provided)
73+ connFactory := config .ConnFactory
74+ if connFactory == nil {
75+ connFactory = func (ctx context.Context , target string , defaultOpts []grpc.DialOption ) (grpc.ClientConnInterface , error ) {
76+ return grpc .NewClient (target , defaultOpts ... )
77+ }
78+ }
79+
8680 // Create LocalResolverFactory (no custom StateProvider)
8781 factory , err := NewLocalResolverFactory (
8882 ctx ,
8983 wasmRuntime ,
9084 wasmBytes ,
91- resolverStateServiceAddr ,
92- flagLoggerServiceAddr ,
93- authServiceAddr ,
9485 config .APIClientID ,
9586 config .APIClientSecret ,
9687 nil , // stateProvider
9788 "" , // accountId (will be extracted from token)
89+ connFactory ,
9890 )
9991 if err != nil {
10092 wasmRuntime .Close (ctx )
@@ -130,19 +122,22 @@ func NewProviderWithStateProvider(ctx context.Context, config ProviderConfigWith
130122 runtimeConfig := wazero .NewRuntimeConfig ()
131123 wasmRuntime := wazero .NewRuntimeWithConfig (ctx , runtimeConfig )
132124
125+ // Build connection factory (use default)
126+ connFactory := func (ctx context.Context , target string , defaultOpts []grpc.DialOption ) (grpc.ClientConnInterface , error ) {
127+ return grpc .NewClient (target , defaultOpts ... )
128+ }
129+
133130 // Create LocalResolverFactory with StateProvider
134131 // When using StateProvider, we don't need gRPC service addresses or API credentials
135132 factory , err := NewLocalResolverFactory (
136133 ctx ,
137134 wasmRuntime ,
138135 wasmBytes ,
139- "" , // resolverStateServiceAddr - not used with StateProvider
140- "" , // flagLoggerServiceAddr - not used with StateProvider
141- "" , // authServiceAddr - not used with StateProvider
142136 "" , // apiClientID - not used with StateProvider
143137 "" , // apiClientSecret - not used with StateProvider
144138 config .StateProvider , // stateProvider
145139 config .AccountId , // accountId - required with StateProvider
140+ connFactory , // connFactory - unused here but passed for consistency
146141 )
147142 if err != nil {
148143 wasmRuntime .Close (ctx )
0 commit comments