@@ -3,14 +3,12 @@ package management
33import (
44 "context"
55 "fmt"
6- "os"
76 "os/exec"
87 "strings"
98 "time"
109
1110 "mcpproxy-go/internal/contracts"
1211 "mcpproxy-go/internal/health"
13- "mcpproxy-go/internal/secret"
1412)
1513
1614// extractHealthFromMap extracts health status from a server map.
@@ -157,61 +155,6 @@ func (s *service) Doctor(ctx context.Context) (*contracts.Diagnostics, error) {
157155 return diag , nil
158156}
159157
160- // findMissingSecrets identifies secrets referenced in configuration but not resolvable.
161- // This implements T041: helper for identifying which servers reference a secret.
162- func (s * service ) findMissingSecrets (ctx context.Context , serversRaw []map [string ]interface {}) []contracts.MissingSecretInfo {
163- secretUsage := make (map [string ][]string ) // secret name -> list of servers using it
164-
165- for _ , srvRaw := range serversRaw {
166- serverName := getStringFromMap (srvRaw , "name" )
167-
168- // Check environment variables for secret references
169- if envRaw , ok := srvRaw ["env" ]; ok {
170- if envMap , ok := envRaw .(map [string ]interface {}); ok {
171- for _ , valueRaw := range envMap {
172- if valueStr , ok := valueRaw .(string ); ok {
173- if ref := parseSecretRef (valueStr ); ref != nil {
174- if ! s .isSecretResolvable (ctx , * ref ) {
175- secretUsage [ref .Name ] = append (secretUsage [ref .Name ], serverName )
176- }
177- }
178- }
179- }
180- }
181- }
182- }
183-
184- // Convert map to slice
185- var missingSecrets []contracts.MissingSecretInfo
186- for secretName , servers := range secretUsage {
187- missingSecrets = append (missingSecrets , contracts.MissingSecretInfo {
188- SecretName : secretName ,
189- UsedBy : servers ,
190- })
191- }
192-
193- return missingSecrets
194- }
195-
196- // isSecretResolvable checks if a secret can be resolved (e.g., environment variable exists).
197- func (s * service ) isSecretResolvable (ctx context.Context , ref secret.Ref ) bool {
198- if s .secretResolver == nil {
199- return false
200- }
201-
202- // Environment variables: quick check without resolving to avoid errors
203- if ref .Type == secret .SecretTypeEnv {
204- val , ok := os .LookupEnv (ref .Name )
205- return ok && val != ""
206- }
207-
208- // Attempt to resolve; success indicates the secret exists/works
209- if _ , err := s .secretResolver .Resolve (ctx , ref ); err == nil {
210- return true
211- }
212-
213- return false
214- }
215158
216159// checkDockerDaemon checks if Docker daemon is available and returns status.
217160// This implements T042: helper for checking Docker availability.
@@ -242,54 +185,6 @@ func (s *service) checkDockerDaemon() *contracts.DockerStatus {
242185
243186// Helper functions to extract fields from map[string]interface{}
244187
245- func parseSecretRef (value string ) * secret.Ref {
246- if ! secret .IsSecretRef (value ) {
247- return nil
248- }
249- ref , err := secret .ParseSecretRef (value )
250- if err != nil {
251- return nil
252- }
253- return ref
254- }
255-
256- // detectOAuthIssues identifies OAuth configuration issues like missing parameters.
257- func (s * service ) detectOAuthIssues (serversRaw []map [string ]interface {}) []contracts.OAuthIssue {
258- var issues []contracts.OAuthIssue
259-
260- for _ , srvRaw := range serversRaw {
261- serverName := getStringFromMap (srvRaw , "name" )
262- hasOAuth := srvRaw ["oauth" ] != nil
263- lastError := getStringFromMap (srvRaw , "last_error" )
264- authenticated := getBoolFromMap (srvRaw , "authenticated" )
265-
266- // Skip servers without OAuth or already authenticated
267- if ! hasOAuth || authenticated {
268- continue
269- }
270-
271- // Check for parameter-related errors
272- if strings .Contains (strings .ToLower (lastError ), "requires" ) &&
273- strings .Contains (strings .ToLower (lastError ), "parameter" ) {
274- // Extract parameter name from error
275- paramName := extractParameterName (lastError )
276-
277- issues = append (issues , contracts.OAuthIssue {
278- ServerName : serverName ,
279- Issue : "OAuth provider parameter mismatch" ,
280- Error : lastError ,
281- MissingParams : []string {paramName },
282- Resolution : "MCPProxy auto-detects RFC 8707 resource parameter from Protected Resource Metadata (RFC 9728). " +
283- "Check detected values: mcpproxy auth status --server=" + serverName + ". " +
284- "To override, add extra_params.resource to OAuth config." ,
285- DocumentationURL : "https://www.rfc-editor.org/rfc/rfc8707.html" ,
286- })
287- }
288- }
289-
290- return issues
291- }
292-
293188// extractParameterName extracts the parameter name from an error message.
294189// Example: "requires 'resource' parameter" -> "resource"
295190func extractParameterName (errorMsg string ) string {
@@ -314,11 +209,3 @@ func getStringFromMap(m map[string]interface{}, key string) string {
314209 return ""
315210}
316211
317- func getBoolFromMap (m map [string ]interface {}, key string ) bool {
318- if val , ok := m [key ]; ok {
319- if b , ok := val .(bool ); ok {
320- return b
321- }
322- }
323- return false
324- }
0 commit comments