MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / synthesizeFileAuths

Function synthesizeFileAuths

internal/watcher/synthesizer/file.go:68–212  ·  view source on GitHub ↗
(ctx *SynthesisContext, fullPath string, data []byte)

Source from the content-addressed store, hash-verified

66}
67
68func synthesizeFileAuths(ctx *SynthesisContext, fullPath string, data []byte) []*coreauth.Auth {
69 if ctx == nil || len(data) == 0 {
70 return nil
71 }
72 now := ctx.Now
73 cfg := ctx.Config
74 var metadata map[string]any
75 if errUnmarshal := json.Unmarshal(data, &metadata); errUnmarshal != nil {
76 return nil
77 }
78 t, _ := metadata["type"].(string)
79 provider := strings.ToLower(strings.TrimSpace(t))
80 if provider == "gemini" {
81 provider = "gemini-cli"
82 }
83 if ctx.PluginAuthParser != nil {
84 auths, handled, errParse := parsePluginFileAuths(ctx.PluginAuthParser, pluginapi.AuthParseRequest{
85 Provider: provider,
86 Path: fullPath,
87 FileName: filepath.Base(fullPath),
88 RawJSON: data,
89 })
90 if errParse == nil && handled {
91 auths = compactPluginAuths(auths)
92 if len(auths) == 0 {
93 return nil
94 }
95 perAccountExcluded := extractExcludedModelsFromMetadata(metadata)
96 perAccountModelAliases := extractOAuthModelAliasesFromMetadata(metadata)
97 for index, auth := range auths {
98 if auth == nil {
99 continue
100 }
101 if len(auths) > 1 {
102 coreauth.MarkPluginVirtualAuth(auth, fullPath, index)
103 }
104 auth.CreatedAt = now
105 auth.UpdatedAt = now
106 if auth.Attributes == nil {
107 auth.Attributes = make(map[string]string)
108 }
109 auth.Attributes[coreauth.AttributePath] = fullPath
110 auth.Attributes[coreauth.AttributeSource] = fullPath
111 auth.Attributes[coreauth.AttributeSourceBackend] = coreauth.AuthSourceFile
112 coreauth.SetOAuthModelAliasesAttribute(auth, perAccountModelAliases)
113 ApplyAuthExcludedModelsMeta(auth, cfg, perAccountExcluded, "oauth")
114 coreauth.ApplyCustomHeadersFromMetadata(auth)
115 }
116 return auths
117 }
118 }
119 if provider == "" || provider == "gemini-cli" {
120 return nil
121 }
122 label := provider
123 if email, _ := metadata["email"].(string); email != "" {
124 label = email
125 }

Callers 2

SynthesizeMethod · 0.85
SynthesizeAuthFileFunction · 0.85

Calls 6

ParseJWTTokenFunction · 0.92
parsePluginFileAuthsFunction · 0.85
compactPluginAuthsFunction · 0.70

Tested by

no test coverage detected