Skip to content

Commit 2b4a59e

Browse files
committed
remove Metadata field and use typed auth config
Remove the deprecated Metadata map[string]any field from BackendAuthStrategy and migrate all code to use typed fields (HeaderInjection, TokenExchange). Key changes: - Remove Metadata field from authtypes.BackendAuthStrategy - Update Strategy interface to accept *BackendAuthStrategy instead of map - Update all strategies (header_injection, tokenexchange, unauthenticated) - Update converters to return typed BackendAuthStrategy - Change Backend/BackendTarget structs to use AuthConfig instead of AuthStrategy + AuthMetadata - Update ResolveForBackend to return *BackendAuthStrategy - Update all consumers and tests This provides type safety, better IDE support, and eliminates runtime type assertions throughout the auth subsystem.
1 parent ef8f4bb commit 2b4a59e

39 files changed

+1257
-1058
lines changed

cmd/thv-operator/controllers/virtualmcpserver_vmcpconfig_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,13 @@ func TestConvertBackendAuthConfig(t *testing.T) {
213213
assert.Equal(t, tt.expectedType, strategy.Type)
214214

215215
if tt.hasMetadata {
216-
assert.NotEmpty(t, strategy.Metadata)
216+
// For external auth config refs, check that the strategy type is set
217+
// The actual typed fields (HeaderInjection/TokenExchange) are resolved at runtime
218+
assert.Equal(t, mcpv1alpha1.BackendAuthTypeExternalAuthConfigRef, strategy.Type)
219+
} else {
220+
// For discovered auth, there should be no typed fields populated
221+
assert.Nil(t, strategy.HeaderInjection)
222+
assert.Nil(t, strategy.TokenExchange)
217223
}
218224
})
219225
}

cmd/thv-operator/pkg/vmcpconfig/converter.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,14 @@ func (*Converter) convertBackendAuthConfig(
174174
crdConfig *mcpv1alpha1.BackendAuthConfig,
175175
) *authtypes.BackendAuthStrategy {
176176
strategy := &authtypes.BackendAuthStrategy{
177-
Type: crdConfig.Type,
178-
Metadata: make(map[string]any),
177+
Type: crdConfig.Type,
179178
}
180179

181-
// Convert type-specific configuration to metadata
182-
if crdConfig.ExternalAuthConfigRef != nil {
183-
strategy.Metadata["externalAuthConfigRef"] = crdConfig.ExternalAuthConfigRef.Name
184-
}
180+
// Note: When Type is "external_auth_config_ref", the actual MCPExternalAuthConfig
181+
// resource should be resolved at runtime and its configuration (TokenExchange or
182+
// HeaderInjection) should be populated into the corresponding typed fields.
183+
// This conversion happens during server initialization when the referenced
184+
// MCPExternalAuthConfig can be looked up.
185185

186186
return strategy
187187
}

pkg/vmcp/aggregator/discoverer.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func (d *backendDiscoverer) applyAuthConfigToBackend(backend *vmcp.Backend, back
178178
// In discovered mode, use auth discovered from MCPServer (if any exists)
179179
// If no auth is discovered, fall back to config-based auth via ResolveForBackend
180180
// which will use backend-specific config, then Default, then no auth
181-
useDiscoveredAuth = backend.AuthStrategy != ""
181+
useDiscoveredAuth = backend.AuthConfig != nil
182182
case "inline", "":
183183
// For inline mode or empty source, always use config-based auth
184184
// Ignore any discovered auth from backends
@@ -191,14 +191,13 @@ func (d *backendDiscoverer) applyAuthConfigToBackend(backend *vmcp.Backend, back
191191

192192
if useDiscoveredAuth {
193193
// Keep the auth discovered from MCPServer (already populated in backend)
194-
logger.Debugf("Backend %s using discovered auth strategy: %s", backendName, backend.AuthStrategy)
194+
logger.Debugf("Backend %s using discovered auth strategy: %s", backendName, backend.AuthConfig.Type)
195195
} else {
196196
// Use auth from config (inline mode)
197-
authStrategy, authMetadata := d.authConfig.ResolveForBackend(backendName)
198-
if authStrategy != "" {
199-
backend.AuthStrategy = authStrategy
200-
backend.AuthMetadata = authMetadata
201-
logger.Debugf("Backend %s configured with auth strategy from config: %s", backendName, authStrategy)
197+
authConfig := d.authConfig.ResolveForBackend(backendName)
198+
if authConfig != nil {
199+
backend.AuthConfig = authConfig
200+
logger.Debugf("Backend %s configured with auth strategy from config: %s", backendName, authConfig.Type)
202201
}
203202
}
204203
}

0 commit comments

Comments
 (0)